Resources:
WolframAlpha will convert to decimal. Just type the number in the search bar using the standard notation: 0x7af (hex), 11011b (binary), 0o373 (octal), where 0x denotes hex, 'b' denotes binary, and 0o denotes octal.
1011 1110 0111 0111 1100
+ 1110 - 1011 + 0000 1011 - 0101
---- ---- --------- ----
1010 ________
x 1001 11 | 10011 (include remainder)
----
11100 11010 11001 ~1 ~0
& 10101 | 10001 ^ 10010 -- --
----- ----- -----
((num & 1) != 0)
((num & 15) == 0)
1010 1110 1001 1100 (binary to hex)
11 1001 (binary to hex)
31 (decimal to hex)
67 (octal to hex)
1100 1010 0011 1001 1110 0000 1111 1100
1000 0110 0001 0000 1111 1010 0101 1010
2357 (decimal to binary)
1011 1110 (binary to decimal)
347 (octal to decimal)
A1E (hex to decimal)
0000 0011
Check your work by adding -3 and 3 (you should get all zeros).
(7 mod 9) = 7. (7 mod 3) = 1. (7 mod 7) = 0. (63 mod 9) = 0.
(7 mod 4) = 3. (21 mod 4) = 1.
Create a modulo-n counter for n = 16 using only a bitwise AND operation.
i.e., construct an operation M(x) that will take any
integer x and
only return values y = 0..15. M is also counter, thus if M(x) = 15 then
M(x+1) = 0. For all other values x, if M(x) = y, M(x+1) = y + 1. Test that
your counter is working by applying x = 0, 15, 16 and 17. In modulo-16 the
results should be M(0) = 0; M(15) = 15; M(16) = 0; M(17) = 1. Note: there is
an error in WCG, Ch.3 pg.52. The note at the top of the page should read:
Note: 0x1f = 31 = 2^5 - 1, so n = 32 and m = 5.
E1 << 2 is E1 left-shifted 2 bits; vacated bits are filled with zeros E1 >> 2 is E1 right-shifted 2 bits; vacated bits are filled with zerosWhat does this C function accomplish and what is the purpose of m?
unsigned int n = 176; //unsigned int holds a positive integer in 32 bits
unsigned int m = 1 << 31;
while (m) {
char c = (n & m) ? '1' : '0';
write(1,c,1); // write one character to standard out
m = m >> 1;
}
unsigned int m = 21;
m << 2; # the 2 means shift left by 2 bits
unsigned int m = 64;
m >> 2; # shift right 2 bits
unsigned int m = 9;
m >> 3; # shift right 3 bits
int m = -5;
m << 1;
int m = -8;
m >> 1;