Bitwise operations: Difference between revisions

Content added Content deleted
(added ruby)
(adding Factor)
Line 219: Line 219:
XOR : 11111111 ^ 10101010 = 00000000000000000000000001010101 ( 85)
XOR : 11111111 ^ 10101010 = 00000000000000000000000001010101 ( 85)
NOT : ~ 11111111 = 11111111111111111111111100000000 (-256)</pre>
NOT : ~ 11111111 = 11111111111111111111111100000000 (-256)</pre>

=={{header|Factor}}==
"a=" "b=" [ write readln string>number ] bi@
{
[ bitand "a AND b: " write . ]
[ bitor "a OR b: " write . ]
[ bitxor "a XOR b: " write . ]
[ drop bitnot "NOT a: " write . ]
[ abs shift "a asl b: " write . ]
[ neg shift "a asr b: " write . ]
} 2cleave

outputs:

a=255
b=5
a AND b: 5
a OR b: 255
a XOR b: 250
NOT a: -256
a asl b: 8160
a asr b: 7

=={{header|Forth}}==
=={{header|Forth}}==
: arshift 0 ?do 2/ loop ; \ 2/ is an arithmetic shift right by one bit (2* shifts left one bit)
: arshift 0 ?do 2/ loop ; \ 2/ is an arithmetic shift right by one bit (2* shifts left one bit)