SHL, SHR and the scary stuff inbetween. :)

Blitz3D Forums/Blitz3D Beginners Area/SHL, SHR and the scary stuff inbetween. :)

Myke-P(Posted 2003) [#1]
I want to store data in a more efficient manner. This data is always either 0, 1, 2 or 3.

Hence I decided to store it in blocks of four using Bit shifting, i.e.:

which1 = 0
which2 = 2
which3 = 3
which4 = 2

(binary representation)
00 01 11 01


I 'compile' the data block thus:
outwhich = which1 Or (which2 Shl 2) Or (which3 Shl 4) Or (which4 Shl 6)


First off, is that right for the storage I desire?

Secondly, how do I extract my which1, which2, which3 and which4 back out of "outwhich"?

Looking at the Read/WritePixelFast bit shifting, I thought it should be:

testwhich4 = outwhich Shr 6
testwhich3 = outwhich Shr 4
testwhich2 = outwhich Shr 2
testwhich1 = outwhich


But that doesn't seem to work?

I'm probably doing something really stupid, but any help would be appreciated. :)


Myke-P(Posted 2003) [#2]
Cheers to RetroBooster and HunterSD in #Blitzcoder.

Turns out it was something stupid. :)

testwhich4 = (outwhich Shr 6) And %11
testwhich3 = (outwhich Shr 4) And %11
testwhich2 = (outwhich Shr 2) And %11
testwhich1 = (outwhich) And %11


Cheers peeps.