140 likes | 275 Views
Exercise Class. f rom HW1 to HW3 Author: Zhou Yuwei ( 11302010067@fudan.edu.cn ). HARD RULES. Plagiarism: No Tolerance Forbid C&P and Typo from Network from classmates Punishment 0 point for all!!! Deadline : No Extension. Homework1. 4 C-programs
E N D
Exercise Class from HW1 to HW3 Author: Zhou Yuwei (11302010067@fudan.edu.cn )
HARD RULES Plagiarism: No Tolerance Forbid C&P and Typo from Network from classmates Punishment 0 point for all!!! Deadline: No Extension
Homework1 4 C-programs conversion
Problem 2. Convert the numbers below in given base to target radix HW 1 • a) (100101001)2 (451) 8 • b) (C32148)16 (12788040)10 • c) (33195)10 (1000000110101011)2 • d) (7242)8 (EA2)16 • e) (5D76CB)16 (10111010111011011001011)2 • f) (101110101101)2 (BAD)16
Homework2 Binary representation Equation Distinguish the machine order Bit operator
Problem 1. You have a 6-bit machine using two’s complement arithmetic for signed integers. short integers are encoded using 3-bits. Right shifts of ints are arithmetic. Sign extension is performed whenever a short is casted to an int. And now you get definitions: int a = -29; short b = (short) a; int x = -21; short y = (short) x; unsignedint ux = x; short sp = -2; int p = sp; int q = -31; HW 2
Problem 2 .It’s a pair of unsigned Multiplication, and each value is represented by 4-bits unsigned integer. Please solve the equation. 0011 * x + 0100 * y = 1001 …(a) 0100 * x + 0011 * y = 1000 … (b) HW 2 (b)-(a) 0001 * x + 1111 * y = 1111 ……(c) (c)*2 0010 * x + 1110 * y = 1110 ……(d) (c)+(d) 0011 * x + 1101 * y = 1101 ……(e) (e)-(a) 1001 * y = 0100 y = 0100 0011 * x = 1001 x = 0011 result: x = 0011, y = 0100
Problem 3 ,write the codes to distinguish the “big endian” and “little endian” order HW 2 /* * hufflepuff – return 1 if little endian * else return 0 */ inthufflepuff(void) { inti= 1; char*p = (char *)&i; return*p; } p &i
Homework3 Linux commands Signed and unsigned Memory operation
Problem 2, Signed and unsigned HW 3 • B2T(X) —— binary to two’s-complement • B2U(X) —— binary to unsigned ——refer to chapter 2.2.2 & 2.2.3
Problem 3, Byte OrderingSuppose a 16-bits little-endian machine has two interfaces WRITE and READ to access memory. WRITE(addr, value) stores the 16-bits valueinto memory with the start address addr; Read(addr) reads a byte data from the memory at address addr. Then see the following code pieces and give your answer in hexadecimal form for the READ operations.WRITE(0x4001, 0xF3E2)WRITE(0x4004,0xAB)WRITE(0x4003,0x12)Then,READ(0x4002): 0xF3 READ(0x4004): 0x0 HW 3
Problem 3, Byte Ordering HW 3 WRITE(0x4001, 0xF3E2)WRITE(0x4004,0xAB)WRITE(0x4003,0x12)Then,READ(0x4002): 0xF3 READ(0x4004): 0x0 0xE2 0xF3 0x12 0x00 0xAB WRITE(0x4004, 0x00AB) WRITE(0x4003, 0x0012) WRITE(0x4001, 0xF3E2) 0x00
THANKS …Any question,contact your TAs Author: Zhou Yuwei (11302010067@fudan.edu.cn )