Lecture 8 Flashcards
Bitwise operations in C and Unix Config
Rightmost bit is
the least significant LSB or low-order bit
leftmost bit is
the most significant bit (MSB) or high-order bit
byte is collection of
8 bits
a bit is
a single binary digit
memory
is just an array of bytes
The binary number 01100100 represents
100 ( 2^2 + 2^5 + 2^6)
two’s complement notation
handling of negative numbers in computers
If the leftmost number is 1
then it can be represented as a negative number
11111111 represents
-1
if w1 and w2 are both defined as short int , and w1 is set equal to 25 and
w2 is set equal to 77, then the C statement w3 = w1 & w2; What is the value assigned to w3?
9
w1 0000000000011001 = 25
&
w2 0000000001001101 = 77
———————————-
w3 0000000000001001 = 9
It compares the value in w1 and w3
Bitwise ANDis frequently used for
MASKING operations; where you use a specific binary value (like 3) to selectively “mask” certain bits of another number (here, w1), effectively zeroing out the bits that don’t correspond to 1 in the mask
w1 is 11001010 (an 8-bit binary number), and 3 is 00000011.
Performing w1 & 3 will look
w1: 11001010
3 : 00000011
—————-
w3: 00000010
Is word &= 15; equivalent to word = word & 15; ?
yes
What is the equivalent to Stress = Stress & 100
Stress &= 100;
Is the bitwise AND operator & the same as the logical AND operator &&?
NO
When dealing with 32- of 64-bit computers, which notation is most often used
Hexadecimal
the octal constant of 0177 represents what decimal value
=127 (1 * 64 + 7 * 8 + 7)
to display an integer in octal?
printf( %o)
Convert the decimal number 2345 into hexadecimal
0x929
Convert the decimal number 512 into octal.
1000 (in octal).
Convert Hexadecimal 0x1A3 to Decimal
419
Convert Octal 725 to Decimal
469