I'm currently coding to another company's specs and need to convert a decimal (byte size of payload being posted to their servers) to a two byte binary representation.
I'm fairly new to binary numbers other than the basics you learn in school. The specs of the company I'm connecting to include the following example:
...place 502 binary (0x01 0xF6) two-byte header...
I've been working with PHP in order to produce the same results they use in their example. However, while I can use dexhex to produce 1f6 as a string, it's not two bytes and it's not represented in the format I need for my communcation.
$var = dechex( 502 ); // produces string 1f6 (3 bytes) (no good)
$var = decbin( 502 ); //produces string 111110110 (9 bytes) (no good)
I would greatly appreciate some help on this subject or at least some pointers to get me going in the correct direction. Thank you very much for your time.