Finding the correct Endian (bit significance) can be frustrating when trying to interface with a device. It’s an additional variable that makes debugging a hardware interface more difficult and can lead to unwanted and sometimes unseen errors.
When you read hex characters it is generally straight forward
0x01 = 1, 0x02 =2… 0x0a=10, 0xa4 = 164
There is a great tutorial on wikihow if you need a refresher on hex to decimal conversion http://www.wikihow.com/Convert-from-Decimal-to-Hexadecimal.
For hardware interface developers (specifically using serial communications) there is an additional step that is needed to take a returned hex value and make it into a useable number. This is finding out the bit significance of the architecture and rearranging the bytes return the actual number.
A simple analogy that we are all used to is date formatting. Years, Months, Days? Which way should we order it?
Days are the least significant measure of time and Years are the most significant measure of time. If you were to map Big, Little, and Middle (more about that later) Endian’s to dates it would look something like this:
|Little Endian||Least Significant To Most Significant||dd/MM/yyyy||European/British|
|Middle Endian||No real order in significance||MM/dd/yyyy||American|
|Big Endian||Most Significant To Least Significant||yyyy/MM/dd||Japanese|
This can complicate things without knowing the Endian we won’t know if 05/01/2000 is May 1st 2000 or January 5th 2000. In the same way the resulting data causes similar problems for hardware interface developers.
16 Bit Endians
Luckily with 16 bit values there are only 2 combinations for bit significance – Big and Little.
Consider the 16 bit number: 0xA3 B5
32 Bit Endians
32 Bit numbers are more complicated as there are essentially 4 different combinations:
Big Endian, Little Endian, and the bastards of the Endian’s Middle Endian. Middle Endian is a loose phrase used to describe an architecture that uses neither Big nor Little Endian. It actually comes in 2 forms which I coined “Middle-Big” and “Middle-Little” they are described as follows:
Consider a 32 bit hex number: 0xA3 B5 C2 D1
SCADACore offers a free – simple field app to help to quickly translate endians into Floats and Integers.
Click here for SCADACore’s Data Analyzer