hi,
This is a set of functions for manipulating bits:
- rotate bits left/right
- shift bits left/right
- XOR
- NOT
- READBIT
I hope it will be useful to someone
rem FUNCTIONS
rem
rem a: integer value
rem b: value for shifting/rotating bits
rem
rem rotate bits on the right
function ROR(a,b)
if b>0 and b<32
tmp1=(a&2147483647)/(2^b)
sgn=(a<0)*2^(31-b)
tmp2=(a&((2^b)-1))*2^(32-b)
result=(tmp1|sgn|tmp2)
else
result=a
endif
endfunction result
rem rotate bits on the left
function ROL(a,b)
if b>0 and b<32
d2=(2^(32-b))-1
d=2147483647-d2
tmp1=(a&d2)*(2^b)
sgn=(a<0)*2^(b-1)
tmp2=(a&d)/(d2+1)
result=(tmp1|sgn|tmp2)
else
result=a
endif
endfunction result
rem shift bits on the right
function SHR(a,b)
if b>=0 and b<32
sgn=(a<0)*(2^(31-b))
tmp2=(a&2147483647)/(2^b)
result=(sgn|tmp2)
else
result=0
endif
endfunction result
rem shift bits on the left
function SHL(a,b)
if b>=0 and b<32
result=a*(2^b)
else
result=0
endif
endfunction result
rem exclusive or
function XOR(a,b)
result=(a|b)-(a&b)
endfunction result
rem NOT
function NOT(a)
result=0-(a+1)
endfunction result
rem reads any bit
function READBIT(a,b)
if b>=0 and b<32
result=a&(2^b)
else
result=0
endif
endfunction result
DirectX 9.0c (February 2010)/ DBClassic v1.13