CS计算机代考程序代写 Supplementary Answers

Supplementary Answers
1. How many bits in a byte? 8
2. What is the biggest number we can create with 4 bits? 16 = 2^4 i.e., [0 – 15] = [0 – 2^4-1]
3. What is the biggest number I can make with 1 byte? Unsigned: 2^8 – 1 (0->255) 256 values
4. What if I need the number to be signed – what is the biggest, what is the smallest?
As a programmer, do you think this range is large enough to represent an integer? Nope. Signed: highest order bit is sign bit.
Highest +ve # 01111111 = 2^7 – 1 = 127 Lowest –ve # 10000000
to get decimal value (negate) => 01111111 (add 1) => 10000000 = -2^7 = -128
5. With 4 bytes what is the range for signed integers? -2^312^31 – 1
6. How many 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
2^4 = 16 bytes
7. How many addresses can we make with 8 bits and therefore how many bytes of memory would we be able to address with 1 byte addresses?
2^8 = 256 bytes
8. How many addresses can we make with 16 bits and therefore how many bytes of memory would we be able to address with 2 byte addresses?
2^16 = 65,536 bytes = 64 KB (1KB = 1024bytes) (64KB = 1024*64 bytes)
9. How many addresses can we make with 32 bits and therefore how many bytes of memory would we be able to address with 4 byte addresses?
2^32 = 4 GB (1GB = 1024KB)
10. Convert 0b101010010100010 to hex
0x54A2
11. Convert 0x4C1B to binary
0b100110000011011
12. Convert 0d456 to hex 0x1C8
13. Convert 0xA1B2 to decimal 41394
14. 0xDC4 – 0xCF9 0xCB
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 0000 1100, 12, 0x0C 0001 1000, 24, 0x18 0011 0000, 48, 0x30 0110 0000, 96, 0x60 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
0000 0011, 3, 0x3 0000 0001, 1, 0x0 0000 0000, 0, 0x0 0000 0000, 0, 0x0

17. Convert -14 to binary (1 byte) and hexadecimal
!0000 1110 1111 0001 + 1 1111 0010
-> 1111 0001 -> 1111 0010
-> 0xF2
18. What is the result of the following statement in (give the binary, hexadecimal and decimal): –1410 >> 1
First do the 2’s complement
1111 0010 >> 1
0111 1001 0x79, 121 WRONG filling the leading bit with 0 makes it positive 1111 1001 0xF9, (!1111 1001 + 1-> 0000 0111) -> -7 CORRECT
For arithmetic shift sign bit gets copied into highest order bit 19. Extending and Truncating
biib
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
10 0000 0000 0000 0000 0000 0000 0000 1010 0x0000000A 0xA 10
-7 1111 1111 1111 1111 1111 1111 1111 1001 0xFFFFFFF9 -7
-125 1111 1111 1111 1111 1111 1111 1000 0011 0xFFFFFF83 -125
128 0x00000080 0x80 -128
300 0x0000012c 0x2c 44
-4909 0xFFFFECD3 0xD3 -45
20. & is a bitwise operator (different from &&) What is the result of the follow operations?
0100 1101 &1111 1111 0100 1101
0x4d 0100 1101 &0xff &0000 1111 0x4d 0000 1101
0x4d 0x3da14d9b &0x0f &0x0000ff00 0x0d 0x00004d00
21. | is a bitwise operator (different from ||) What is the result of the follow operations?
0010 1101 |0011 1111 0011 1111
0x40 0100 0000 |0x0f |0000 1111 0x4f 0100 1111
0x4d 0x00004d00 |0x0f &0x9b000000 0x4f 0x9b004d00

22. What will display to the screen for the following snippets of code
int i = 0x7A << 16; out.printf("%x\n", i); 7A0000 int i = ((byte) 0x9F)<< 8; out.printf("%x\n", i); FFFF9F00 int i = 0x9F<< 8; out.printf("%x\n", i); 9F00 int i = ((byte) 0x2F)<< 12; out.printf("%x\n", i); 2F000 int i = 0x2F<< 12; out.printf("%x\n", i); 2F000 int i = 0xFF234212 >> 12; out.printf(“%x\n”, i);
FFFFF234 out.printf(“%x\n”, i); FF2
int i = 0xFF2342 >> 12;