Shop OBEX P1 Docs P2 Docs Learn Events
PropBasic: Bit manipulation / arithmetic — Parallax Forums

PropBasic: Bit manipulation / arithmetic

VonSzarvasVonSzarvas Posts: 3,525
edited 2010-09-07 16:06 in Propeller 1
Help!

I am reading the sector size from an SD card. The required bits are happily shift'd-in and spread across 3 bytes thus:

10000011 11000100 11101100

This is the selection of bits I need to extract, which should represent 3859 !

11 11000100 11

If I were to mask the bits, I would imagine doing this:

b1 = b1 & 3
b2 = b2
b3 = b3 & 192

But how do I "join" the 3 bytes into 1 integer (or long!) that equals 3859 ?

Hopefully there is an insanely efficient way of doing this. I would be very happy to learn it!

Max.

Comments

  • BeanBean Posts: 8,129
    edited 2010-09-07 15:35
    Try something like:
    b1 = b1 & 3
    b1 = b1 << 8
    
    b1 = b1 + b2
    b1 = b1 << 8
    
    b3 = b3 & 192
    b1 = b1 + b3
    

    Bean
  • VonSzarvasVonSzarvas Posts: 3,525
    edited 2010-09-07 16:03
    ... gosh that was fast! Thank you.

    As I try out the code, I seem to stumble at this line:

    tmp = 1 << SD_blocksize

    It seems to assign 0 value to tmp, whereas I would have expected 512 (being that SD_blocksize=9)

    Is it possible that I cannot SHL this way ? ... hmm... or maybe its my DEBUG_TX falling over at 255...
  • VonSzarvasVonSzarvas Posts: 3,525
    edited 2010-09-07 16:06
    ... yes, the DEBUG_TX will need upgrading to the 21st century ! I do miss the WATCH sometimes.. :)
Sign In or Register to comment.