Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CSI104: Foundations Of Computer Science

Duration: 90’

Lab 1:
Scoring scale: 10

Exercise 1 (2.5 marks): Convert decimal numbers(+last number of student code)


to binary and and vice versa.

Decimal Binary Binay Decimal

12 1100 101001 41
16 10000 1001010 74
20 10100 11101111 239
26 10110 100101 37
52 110100 1101.11 13.75
133 1000 0101 111111.11 63.75
70 1000110 1.00101 1.15623
64 1000000 101111.1 47.5
7.625 111.101 1.00001 1.03125
9.5 1001.1 11.001 3.125
10.75 1010.11 10001.11 17.75

Exercise 2 (2.5marks): Convert decimal numbers(+last number of student code) to


binary and hexadecimal ones

Decimal Binary Hexa. Decimal 16-bit Binary Hexadecim


al

16 10000 10 262 0000 0001 0000 0110 106


122 0111 1010 7A 200 0000 0000 1100 1000 C8
161 1010 0001 A1 194 0000 0000 1100 0010 C2
170 1010 1010 AA 322 0000 0001 0100 0010 142
186 1011 1010 BA 525 0000 0010 0000 1101 20D
40 0010 1000 28 270 0000 0001 0000 1110 10E
75 0100 1011 48 548 0000 0010 0010 0100 224
79 0100 1111 4F 823 0000 0011 0011 0111 337
87 0101 0111 57 1029 0000 0100 0000 0101 405
102 0110 0110 66 2066 0000 1000 0001 0010 812
109 0110 1101 6D 74 0000 0000 0100 1010 4A

Exercise 3 (1 marks): Compute (b: binary, q: octal, h: hexadecimal)

235q + 547q = ?q = ?b
=1004q = 001 000 000 100b

1D7Bh + 26FA7h = ?h = ?b
= 28D22h = 0010 1000 1101 0010 0010b

1101001101b - 10110110b =?b


= 0010 1001 0111b

3624q – 377q =?q = ?b


=3225q = 0110 1001 0101b

2AD7h – 1FBh = ?h = ?b
=28DCh = 0010 1000 1101 1100b

32Ah – 516q = ?h = ?b
= 1DCh = 0001 1101 1100b

62ACh – 1000101b= ?q
=61147q

Exercise 4 (1 marks)

Two integers A and B are stored in two’s complement format. Show how B is added to
A:

1. A = (00011001)2 , B = (01010110)2(step by step)

B= 01010110

A= 00011001 A+B=0110 1111

0+1=1, 1+0=1, 1+0=1, 0+1=1, 1+1=0 nho 1, 0+0=0, 1 nho = 1, 1+0=1, 0+0=0

2. A = (00011010)2, B = (11101010)2(step by step)


A= 0001 1010

B= 0001 0110 (lat bit 0 thanh 1 xong cong 1) 0011 0000

0+0=0, 1+1=0 nho 1, 1+0=1 nho 1=0, 1+0=1 nho 1=0, 1+1=1 1nho ,0+0=1 1 nho,
0+0=0…

Exercise 5 (3 marks)
1- Store -31(+last number of student code) in an 8-bit memory location using sign-
and-magnitude representation.(step by step)
Bieu dien 31 la 11111
So am => Bit dau la 1 => 1 11111

2- Show the Excess_127 (single precision) representation of the decimal number


13.75(+last number of student code)(step by step)

13.75 sang binary = 1101.11


3 lan sang trai =>So mu bang 3
127+3=130=>binary 1000 0010
Bit dau 0 vi la so duong
Dau phay dong 1.1011
=>bieu dien: 0 10000010 10110000000000000000000

3- The bit pattern (11001010000000000111010100001111)2 is stored in memory in


Excess_127 format. Show what is the value of the number in decimal notation.
Solution(step by step)
Bit dau = 1
Bit so mu = 1001 0100b => 148d => so mu=148-127=21
Bit con lai 0000000111010100001111 chuyen sang decimal = 0.40625
Bieu dien = = (-1)^1 x 2^21 x (1 + 0.40625) = -2097151.59375

You might also like