Big/little endian in byte conversions

Recommended Posts

OK, let's try to post this topic just one more time.

I have a serial device sending a 4 byte double word following big endian convention. That is, the most significant word comes first and bits are ordered most significant first. Or at least that's how I interpret this screen shot:


The problem is I can't find a suitable combination of byte conversion commands to convert the word to a value.

Right now I grab the data as a string using Device.myInst.Read(4) then convert to

Link to comment
Share on other sites

If one of the To.xx() or From.xx() functions doesn't work, you can always just rearrange the bytes yourself so it works in one of those functions:

private string datain =

private data = asca(datain)

private out

out[0] = datain[2]

out[1] = datain[3]

out[2] = datain[0]

out[3] = datain[1]

Link to comment
Share on other sites

Yes, reversing the byte order manually is the quickest way to get the the right #s:

while (streamOn) // and until it's turned OFF

data[3] = Device.FIS.Read(1) // read 4 bytes of data, reversing order of bytes from

data[2] = Device.FIS.Read(1) // most significant to least

data[1] = Device.FIS.Read(1)

data[0] = Device.FIS.Read(1)


Link to comment
Share on other sites


This topic is now archived and is closed to further replies.