View Full Version : problems with converting a byte variable to high and low nib

Mikael S
02-01-2010, 02:53 AM

This is my problem:

For example: I have a variable that have a value of 24

variable1 = 24

and when i try to convert this into two other variables with highnib and lownib:

variablehigh = variable1.highnib
variablelow = variable1.lownib

the output of those will be

variablehigh = 1
variablelow = 8
instead of 2 and 4.

What am i doing wrong here? They are declared as byte's but i have also tried to declare them as words.

Thanks for any help!

Mike Green
02-01-2010, 02:58 AM
"24" is a decimal number and the results you get with .highnib and .lownib are correct. The number 24 is stored in a byte as 2 to the 4th power plus 2 to the 3rd power or %00011000 or $18. If you want the digits of the decimal representation of a number like "24", you would use the DIG operator. Read the description of this in BASIC Stamp Syntax and Reference Manual.

Mikael S
02-01-2010, 03:19 AM
Thanks, that is the command i needed!