Supplementary Questions
1. How many bits in a byte?
2. What is the biggest number we can create with 4 bits?
3. What is the biggest number you can make with 1 byte?
4. What if you need your data to be a signed number – what is the biggest number, what is the smallest number?
As a programmer, do you think this range is large enough to represent an integer?
5. With 4 bytes what is the range for signed integers?
6. How many unique addresses can we make with only 4 bits and therefore how many bytes of memory would we
be able to address with 4 bit addresses?? NOTE: addresses are unsigned
7. How many unique addresses can we make with 8 bits and therefore how many bytes of memory would we be able to address with 1 byte addresses?
8. How many unique addresses can we make with 16 bits and therefore how many bytes of memory would we be able to address with 2 byte addresses?
9. How many unique addresses can we make with 32 bits and therefore how many bytes of memory would we be able to address with 4 byte addresses?
10. Convert 0b101010010100010 to hex
11. Convert 0x4C1B to binary
12. Convert 0d456 to hex
13. Convert 0xA1B2 to decimal
14. 0xDC4 – 0xCF9
15. What are the results of the following statements (give the binary, decimal and hexadecimal representation)? NOTE: 0000 0110 is in base 2. The value after << is the number of shifts
- 0000 0110 << 1
- 0000 0110 << 2
- 0000 0110 << 3
- 0000 0110 << 4
16. What are the results of the following statements (give the binary, decimal and hexadecimal representation)? The value after >> is the number of shifts
– 0000 0110 >> 1
– 0000 0110 >> 2
– 0000 0110 >> 3
– 0000 0110 >> 4
17. Convert -14 to binary (1 byte) and hexadecimal
18. What is the result of the following statement in (give the binary, hexadecimal and decimal): –1410 >> 1
19. Extending and Truncating
biib 10 128
-7 300 -125 -4909
20. & is a bitwise operator (different from &&) What is the result of the follow operations?
0100 1101 0x4d 0100 1101 0x4d 0x3da14d9b &1111 1111 &0xff &0000 1111 &0xf &0xff00
21. | is a bitwise operator (different from ||) What is the result of the follow operations?
0010 1101 0x40 0100 0000 0x4d 0x00004d00 |0011 1111 |0x0f |0000 1111 |0x0f &0x9b000000
Extending: from byte to Integer (signed ext) byte b = value
int i = b
What is stored in i when b is
Truncating: from integer to byte
int i = value
byte b = (byte) i;
What is the value stored in b when i is
22. What will display to the screen for the following snippets of code
int i = 0x7A << 16; out.printf("%x\n", i);
int i = ((byte) 0x9F)<< 8;
out.printf("%x\n", i);
int i = 0x9F<< 8;
out.printf("%x\n", i);
int i = ((byte) 0x2F)<< 12;
out.printf("%x\n", i);
int i = 0x2F<< 12;
out.printf("%x\n", i);
int i = 0xFF234212 >> 12;
out.printf(“%x\n”, i);
int i = 0xFF2342 >> 12;
out.printf(“%x\n”, i);
23.