Anonymous user
Bitwise operations: Difference between revisions
m
→{{header|D}}: remove incorrect; added shifts (not tested, hard time compiling gdc)
(→{{header|C}}: added comment about missing rotations, required by task description) |
m (→{{header|D}}: remove incorrect; added shifts (not tested, hard time compiling gdc)) |
||
Line 231:
=={{header|D}}==
<lang d>module bitwise ;
import std.stdio ;
Line 240 ⟶ 239:
writefln(" OR : %8b | %08b = %032b (%4d)", a, b, a | b, a | b) ;
writefln("XOR : %8b ^ %08b = %032b (%4d)", a, b, a ^ b, a ^ b) ;
writefln("LSH : %8b << %08b = %032b (%4d)", a, b, a << b, a << b) ;
writefln("RSH : %8b >> %08b = %032b (%4d)", a, b, a >> b, a >> b) ;
writefln("NOT : %8s ~ %08b = %032b (%4d)", "", a, ~a, ~a) ;
}
// shift and rotation are not available
void main() {
int a = 0b11111111 ; // bit literal 255
int b =
testbit(a,b) ;
}</lang>Output:
<pre>Input: a = 255 , b =
AND : 11111111 &
OR : 11111111 |
XOR : 11111111 ^
LSH : 11111111 << 00000010 = 00000000000000000000001111111100 (1020)
RSH : 11111111 >> 00000010 = 00000000000000000000000000111111 ( 63)
NOT : ~ 11111111 = 11111111111111111111111100000000 (-256)</pre>
|