Shop OBEX P1 Docs P2 Docs Learn Events
Window variable modifier — Parallax Forums

Window variable modifier

philipad23philipad23 Posts: 44
edited 2006-01-29 05:13 in BASIC Stamp
HI all!,

I am trying to get as a variable the first 3 nibbles of a word but i dont know how to write the variable modifier.

I get the last nibbles like this:

a VAR word
b VAR a.LOWNIB

but how I get the other three?

I thought it was

a VAR word
b VAR a.LOWNIB
c VAR c.NIB1...3······ but this dont seem to work

anyone can help me?.....

·

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-29 04:31
    You betcha... give these a try: myWord.NIB3 (highest nib), myWord.NIB2, myWord.NIB1, myWord.NIB0 (lowest nib).· If you need to use another variable to select one of the nibbles you can use the LOWNIB modifier like this: myWord.LOWNIB(idx) -- where idx is 0 (lowest nib) through 3 (highest).


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • philipad23philipad23 Posts: 44
    edited 2006-01-29 04:38
    so is not possible to read together the first 12 bits of a 16-bit variable?
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-29 04:52
    If you want to isolate the lower 12 bits of a word you must do this:

    · bVar = aVar & $0FFF

    There is no 12-bit variable type, so bVar must be a Word as well.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • philipad23philipad23 Posts: 44
    edited 2006-01-29 05:01
    it will not work because masking will change the number when isolating to get the higher 12-bits. Maybe I will try to get the 3 nibbles separately and try to reconsctruct the 12-bit number

    Thanks anyway!
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-01-29 05:06
    In the example I gave you, bVar will end up being the lower 12 bits of aVar -- and aVar is not modified.· Now, if you want bVar to be set to the value of the upper 12 bits of aVar, do it like this:

    · bVar = aVar >> 4

    Again, aVar is not modified by this process.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • philipad23philipad23 Posts: 44
    edited 2006-01-29 05:13
    that works great!
    thanks
Sign In or Register to comment.