Hexadecimal is just another way to write down
numbers. It is often more convenient than
decimal, e.g. when we are dealing with numbers that represent byte values or memory addresses. But you really could write down the numbers in either
hexadecimal,
decimal or
octal – whichever you prefer. It's simply a different notation!
Now, when it comes to sending some "commands" over a network, it is much more efficient to encode these commands as numbers rather than text strings. For example, a number like
0x03
requires just a
single byte to transmit, where the text string
"RPSS_NUMOFUSERS" would require 16 bytes! (assuming ASCII or UTF-8).
Also, for the
receiver of the command it is much easier to deal with a numeric value, which, for example, can simply be thrown into a
switch()
statement, rather than having to parse a text string:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
while(true)
{
const uint8_t command = receive_next_command();
switch(command)
{
case RPSS_NUMOFUSERS:
handle_numofusers_command();
break;
case RPSS_STARTGAME:
handle_startgame_command();
break;
/* ... */
default:
abort(); /*unknown command*/
}
}
|