Shop OBEX P1 Docs P2 Docs Learn Events
aliases and modifiers — Parallax Forums

aliases and modifiers

Speaker337Speaker337 Posts: 14
edited 2010-08-25 16:28 in BASIC Stamp
I have a variable.
code var byte
It has three parts. XXX,YY,ZZZ. I want to name these three parts.
I want to name XXX as mode and ZZZ as arrow.
Reading the manual, it should be something like
code var byte
mode var code.bit5...bit7. Yes?
But it doesn't work. I get "variable is already bit sized."
mode var code.highnib gives the expected result, but is 4 bits rather than three.
Can someone point me to an example?

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-08-25 16:28
    You can't break up a byte value the way you want. You can only use 4-bit nibbles and single bits. You will have to use shift operations and bit logical operations to manage the 3 fields (xxx.yy.zzz).

    To extract xxx, use: result = value >> 5

    To extract yy, use: result = (value >> 3) & 3

    To extract zzz, use: result = value & 7

    To insert xxx, use: result = (result & $1F) | (value << 5)

    To insert yy, use: result = (result & $18) | (value << 3)

    To insert zzz, use: result = (result & $F8) | value
Sign In or Register to comment.