Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,46 @@
|
|||
' bitwise operations on byte-sized variables
|
||||
|
||||
v =int( 256 *rnd( 1))
|
||||
|
||||
s = 1
|
||||
|
||||
print "Shift ="; s; " place."
|
||||
print
|
||||
print "Number as dec. = "; v; " & as 8-bits byte = ", dec2Bin$( v)
|
||||
print "NOT as dec. = "; bitInvert( v), dec2Bin$( bitInvert( v))
|
||||
print "Shifted left as dec. = "; shiftLeft( v, s), dec2Bin$( shiftLeft( v, s))
|
||||
print "Shifted right as dec. = "; shiftRight( v, s), dec2Bin$( shiftRight( v, s))
|
||||
print "Rotated left as dec. = "; rotateLeft( v, s), dec2Bin$( rotateLeft( v, s))
|
||||
print "Rotated right as dec. = "; rotateRight( v, s), dec2Bin$( rotateRight( v, s))
|
||||
|
||||
end
|
||||
|
||||
function shiftLeft( b, n)
|
||||
shiftLeft =( b *2^n) and 255
|
||||
end function
|
||||
|
||||
function shiftRight( b, n)
|
||||
shiftRight =int(b /2^n)
|
||||
end function
|
||||
|
||||
function rotateLeft( b, n)
|
||||
rotateLeft = (( 2^n *b) mod 256) or ( b >127)
|
||||
end function
|
||||
|
||||
function rotateRight( b, n)
|
||||
rotateRight = (128*( b and 1)) or int( b /2)
|
||||
end function
|
||||
|
||||
function bitInvert( b)
|
||||
bitInvert =b xor 255
|
||||
end function
|
||||
|
||||
function dec2Bin$( num) ' Given an integer decimal 0 <--> 255, returns binary equivalent as a string
|
||||
n =num
|
||||
dec2Bin$ =""
|
||||
while ( num >0)
|
||||
dec2Bin$ =str$( num mod 2) +dec2Bin$
|
||||
num =int( num /2)
|
||||
wend
|
||||
dec2Bin$ =right$( "00000000" +dec2Bin$, 8)
|
||||
end function
|
||||
Loading…
Add table
Add a link
Reference in a new issue