Hex data format

Hello and apologies if this is posted in the wrong section I had some debate over it.

I want to know the reason why hex codes are used to transmit data over infrared apposed to just binary versions of decimal numbers, what are the advantages and reasons for this choice.

Take sample data with a id of 900 and command of 690 sent with no deliminator I could convert this to binary and then send it so my question is why convert it to hex.

My initial conclusion is that it could possibly be smaller data length but I cannot see any evidence in my conversions.

Decimal: 900690
Hexadecimal: DBE52

Decimal binary--------: 11011011111001010010
Hexadecimal binary: 11011011111001010010

Looking forward to hearing your responses.

6 decimal digits times 4 bits equals 24 bits
5 hexadecimal digits times 4 bits equals 20 bits

That is from your example numbers.

Computers work with powers of 2 so hexadecimal is a logical choice. BCD is basically there for display to humans.

The computer doesn't care. It's all binary in the computer.

Hex can be more efficient, since you can store the values 0-99 as decimal (BCD) in a byte or 0-FF (0-255) as hex in a byte.

The biggest advantage to hex is for humans (programmers), especially programmers that do hardware-related microcontroller programming (firmware) where binary values are often important to know. That's because you easily learn to convert numbers of any size between hex & binary in your head. ...Every nibble converts exactly to a hex value.

I write a hex value to an 8-bit or 16-bit parallel port, I know the values on all of the pins without making any calculations.*

For example, if I have 0101 0101 0001 0001 (spaces added for readability)
That converts to:
5511 Hex or 21777 Decimal. I can do the hex conversion in my head because 0101 always converts to 5 and 0001 always converts to 1. I used a calculator to get the decimal value.

  • Port commands aren't that common with the Arduino because the compiler has I/O commands for individual pins.

Okay I'm not sure if I understand this hex is more efficient for programmers to use and a preferred working data format?

Sterretje your post doesn't make sense for it to be 4 bits less if I take the sample data 900640 I am actually trying to use two 10 bits of data here because there will be two 10 bit values, now I convert the decimal to binary and then the decimal to hex with final conversion back to binary from hex and compare the two they are the same data length.

The application is in infrared which transmits binary data using pulse length modulation however if I have the user enter a number which will be a decimal day 1024 which is 10 bits what is the advantage of now converting this to hex and then to binary for transmission as appose to just converting straight to binary.

I also have to decode the hex on the other side to decimal so why do commercial products such as TV remotes send hex.

I'm not seeing the advantage here other than preference and standard practice really.

You're correct, it does not make sense. Or it actually did make when I was responding to your message; I thought you were talking about BCD. Else there is no such thing as decimal binary or hexacedimal binary; binary is binary.

You don't need to convert; you (might) need to convert text to number, but that's all.

Shandy:
I want to know the reason why hex codes are used to transmit data over infrared apposed to just binary versions of decimal numbers, what are the advantages and reasons for this choice.

I think it is important to see the program code that gave rise to that question.

Many programs are written using Hex notation for numbers but without seeing the code it is not at all certain that it is sending the characters of the Hex notation or the binary value underlying that.

For example Serial.write(76); Serial.write(0x4C); and Serial.write(0b01001100); all send exactly the same thing.

...R

I want to know the reason why hex codes are used to transmit data over infrared apposed to just binary versions of decimal numbers

As far as I know, Infrared commands ARE transmitted as binary. The user interface to the program may be ascii decimal, or ascii hex, or something else. Without knowing which code or specification you are looking at, it's hard to say what is actually going on. (Some IR controllers may communicate in a different format, for ease of programming and debugging (some programming languages and/or communications paths have difficulties with some binary values sent as characters, but the letters+numbers are almost always safe.)
It's pretty safe to say that IT com is probably byte-oriented (or less); so if you have a number like 680 to transmit, you have to re-factor it into multiple bytes somehow, because 680 doesn't fit in a single byte.

HI,

I think what folks are saying is, the computer stores EVERYTHING as a binary number.

Hex, Decimal, and binary are only ways for the human to communicate with the computer, in the compiler or interpreter all the numbers (and commands) are converted to binary.

So when you see 0b1010100111 or 0xDEF0 or 54928 the compiler sees the binary equivalents.

If you put a logic analyzer on your IR sensor or transmitter you would see a string of 1's and 0's.

Youtube has a video (search for "How to Use a Logic Analyzer") that gives some background and shows an example of the captured binary.

In addition to your IR sensors, UARTS, USB, SPI, I2C all communicate with binary signals (aka numbers).

Hope this helps

Hex is a convient way to deal with long binary strings for humans without making errors, its really
hard to memorize a string of 16 ones/zeroes, easy to remember 4 hex digits. And you can easily
figure out which bits are set.

Its not perfect, its hard to shift a hex number left by 1 position mentally (easy for 4 or 8 or 12...)

But as pointed out above, this is just a view onto the real stored binary, always.

Thank you all for your words, so specifically the format such as hex, binary, ect is just for human use and the chosen format so I can go and store my infrared command codes in decimal and not have to convert numbers to hex every time.