PBasic code to convert base10 to HEX and then back to base10
arnold113
Posts: 43
HELP ANYONE!!! I have a 4 digit base10 number in a reg(word). I need to convert it to a HEX number so I can seperate the highbyte into one reg and the lowbyte into another reg, do some manipulating of the two regs and then convert both back into base10 numbers. I haven't been able to get it done yet. PLEASE HELP. Thanks. Arnold
Comments
If your variable is NUM, then use NUM.HighByte to get the high byte, and NUM.LowByte to get the low byte.
You can manipulate NUM.HighByte and NUM.LowByte as you please. The result is always available in NUM.
If you got highbyte = 9 and lowbyte = 0 then your number was 2304 (decimal) or $0900 hex.
Do you want to manipulate the 23 and the 04 parts?
If so, then use:
HB = NUM / 100
> i.e. (2304 / 100) = 23
LB = NUM // 100
> i.e. (2304 // 100) = 04
To put it back after manipulation,
NUM = 100 * HB + LB
Can you post the code you're using?
It sounds like you're not using the correct parameters with your SERIN command.
To post code to the forum use code tags like this:
[noparse] [/noparse]
Without code tags the above text looks like this:
Paste your code between the code tags.
This will preserve
the indentation
and formatting.
With code tags you get: