sample the msb of your byte
if its set add three to your word var
shift left the byte var 1 bit the word 2 bits
repeat for all 8 bits
sample the msb of your byte
if its set add three to your word var
shift left the byte var 1 bit the word 2 bits
repeat for all 8 bits
Warning I'm not a teacher
and if it not?
don't add 3
Warning I'm not a teacher
If you start off with B=0 and C=0 you can skip half those statements and only do the ones where A.x = 1
I wanted it to be shorter, by using loop and
X.Y=Z
but as I can see, you can't use another variable as bit reference, only static values.
uint16_t enlargeYourByte(uint8_t input)
2 {
3 uint16_t x = input;
4 x = (x ^ (x << 4)) & 0x0f0f;
5 x = (x ^ (x << 2)) & 0x3333;
6 x = (x ^ (x << 1)) & 0x5555;
7 return x | (x << 1));
8 }
This is how they do it in C. Can we port this to PBP ?
I think this does it:
Code:Input VAR BYTE Wide VAR WORD X VAR WORD Y VAR WORD EnlargeYourByte: X = Input Y = Input << 4 X = X ^ Y X = X & $0F0F Y = X << 2 X = X ^ Y X = X & $3333 Y = X << 1 X = X ^ Y X = X & $5555 Wide = X << 1 RETURN
Bookmarks