PropBasic: Bit manipulation / arithmetic
VonSzarvas
Posts: 3,525
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.
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
Bean
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...