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}}==
{{incorrect|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 = 0b101010100b00000010 ; // bit literal 1702
testbit(a,b) ;
}</lang>Output:
<pre>Input: a = 255 , b = 1702
AND : 11111111 & 1010101000000010 = 0000000000000000000000001010101000000000000000000000000000000010 ( 170 2)
OR : 11111111 | 1010101000000010 = 00000000000000000000000011111111 ( 255)
XOR : 11111111 ^ 1010101000000010 = 0000000000000000000000000101010100000000000000000000000011111101 ( 85253)
LSH : 11111111 << 00000010 = 00000000000000000000001111111100 (1020)
RSH : 11111111 >> 00000010 = 00000000000000000000000000111111 ( 63)
NOT : ~ 11111111 = 11111111111111111111111100000000 (-256)</pre>