Split and merge a 32-bit float with two 16-bit unsigned integers

I am sharing a code with an example that splits and merges a 32-bit float with two 16-bit unsigned integers.

Especially, when you work with an embedded system, 16-bit unsigned integer (or 8-bit unsigned integer, that is char) is a common format for data transmission. You can use this function when you want to send a 32-bit float variable with these 16-bit data format.

You can also use this function without the LSB-part. For the details, see the code below.

1 thought on “Split and merge a 32-bit float with two 16-bit unsigned integers

  1. Steve

    I’m not certain that this makes sense given your requirements, but my initial thought was Matlab related. (I wrote something a long time ago for using logical with binaries but without that, in just base functions, assuming AInt16 and BInt16 are uint16 arrays with equal numel():

    xout=uint32(base2dec( …
    [char(pad(string(dec2bin(AInt16(:))),16,’left’,’0′)), …
    char(pad(string(dec2bin(BInt16(:))),16,’left’,’0′) …
    ],2));

    Reply

Leave a Reply