Sending a 32 bit value out a serial port
![pogertt](https://forums.parallax.com/uploads/userpics/278/n8XVUBGUDF3MJ.jpg)
I have an application that requires a value greater than 65535 to be output in a serial string.
46 ** 4000· =· 184000· or··· h2······ hCECO
If the upper word is 0, the result is less than 65536
if it is 1, then make HU =6553 and save the left over 6 for later.
If it is 2, then make HU =(65536 *2 = 131072) \ 10 for 13107 and save the 2 for later.
hCECO =52928· then / by 10 for 5292 and save the 8.
13107 + 5292 =18399
The left over 2 +8 =10 so if this is over 9, add one to 18399 for 18400, then subtract 10 from the 2+8 variable.
output the variable representing the 18400, followed by the variable representing the saved remainders, and you have now sent a 32 bit value out the serial port using a controler that likes 16 bit numbers.
Pogertt
46 ** 4000· =· 184000· or··· h2······ hCECO
If the upper word is 0, the result is less than 65536
if it is 1, then make HU =6553 and save the left over 6 for later.
If it is 2, then make HU =(65536 *2 = 131072) \ 10 for 13107 and save the 2 for later.
hCECO =52928· then / by 10 for 5292 and save the 8.
13107 + 5292 =18399
The left over 2 +8 =10 so if this is over 9, add one to 18399 for 18400, then subtract 10 from the 2+8 variable.
output the variable representing the 18400, followed by the variable representing the saved remainders, and you have now sent a 32 bit value out the serial port using a controler that likes 16 bit numbers.
Pogertt
Comments
I hope this helps.· Take care.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com
I have been using your·math·routines for calculating DDS values (32 bits +) .
Many thanks·for such wondeful tools.
But being lazy and so far not fully understnding the "magic" , do you have a sample·code for decimal to hex conversion - I need more that 5 digits decimal precision.
Thanks in advance.
I better look at the code you just published and see if I can modify it for hex.
Sorry