List 4 types of programs that need to perform operations at the bit level:
What are the bitwise shift operators and how do they work?
(may be of any integar type, including char)
unsigned short i, j;
What would the result(in binary) be of the following operations:
How do you read binary numbers (what’s the basic formula as compared to base 10)?
Represent 16, 7 and 21 in binary
In general, it is powers of 2, starting from the right at 2^0 + 2^1, etc. This is the same way our base ten math work. 21 = 1 X 10^0 + 2 * 10^1
16 in binary = 0000000000010000
7 in binary = 0000000000000111
21 in binary = 0000000000010101
What is the binary representation of the following:
What is the precedence (order/priorty) or a bitwise shift operator?
What does i << 2 + 1 mean?
It is lower than arithmatic.
it means i << 3
What are the bitwise “compliment”, “and”, “exclusive or” and “inclusive or” operators? In general, what do they do?
unsigned short, i, j, k;
What affect would the following operations have in binary?
Evaluate the following using binary.
In general how do hexadecimal numbers work?
What is the number 1BC?
Hex numbers are 16 bits, 0-9 + A-F
0-9 is obviously 0-9 and A - F is 10-15
1BC in hex is 444
What is Binary Code Decimal (BCD). Provide the example for the following:
The 4 bit representation of the decimal digit
In general, how does it work to use bitwise operators to access bits?
The easiest way to set bit 4 of i is to use to or the value of i with the hex constant 0x0010:
If we wanted to clear bit 4 of i how would that be done?
i = 0x00ff;
We would need a number whose only different bit is in the 5th position and use the & operator.
i in binary is 00000000111111111
i &= 0x0010 (16)
in binary is 0000000011101111 (and flipping the only different bit, bit 4 (in the 5th position)
What is a bit-field and in general how is it used?
a bit-field is used in a struct, it allows you to set the specific number of bits you want to use to store a value. You would use this when working with direct bits would take up less space than the actual integer values.
Example:
struct exampleStruct{
unsigned int day: 5; //set aside 5 bits
};
In the example above, day can have up to 31 values (24+23+22+21+20 as each 2 represents 1 bit)
What would the following line output?:
unsigned int i = 0X11;
unsigned int j = 0x32F;
printf(“%d %x %04x\n”, i, i, i);
printf(“%d”, j);
17 11 0011
815
