Shop OBEX P1 Docs P2 Docs Learn Events
problems with converting a byte variable to high and low nib — Parallax Forums

problems with converting a byte variable to high and low nib

Mikael SMikael S Posts: 60
edited 2010-01-31 20:19 in BASIC Stamp
Hello

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!


·

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-01-31 19:58
    "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 SMikael S Posts: 60
    edited 2010-01-31 20:19
    Thanks, that is the command i needed!
Sign In or Register to comment.