compsci 210 semester 1 - 2015 tutorial 1. binary to decimal conversion

14
COMPSCI 210 Semester 1 - 2015 Tutorial 1

Upload: priscilla-johns

Post on 30-Dec-2015

230 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

COMPSCI 210

Semester 1 - 2015

Tutorial 1

Page 2: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

Binary to Decimal Conversion

Page 3: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

2.10 Convert the following 2's complement binary numbers to decimal numbers.

a) 1010b) 01011010c) 11111110d) 0011100111010011

Page 4: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

2.10. c --- Solution

• 11111110– sign bit is 1, so this number is negative.– Calculate the 2's complement.

0000001 (flipping the digits above)+ 1 0000010

= -2 (Affix a minus sign in front)

Page 5: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

2.10. d --- Solution • 0011100111010011

sign bit is 0, so this number is positive.

=0*(2^14)+1*(2^13)+1*(2^12)+1*(2^11)+0*(2^10)+0*(2^9)+1*(2^8)+1*(2^7)+1*(2^6)+0*(2^5)+1*(2^4)+0*(2^3)+0*(2^2)+1*(2^1)+1*(2^0)

=1*(2^13)+1*(2^12)+1*(2^11)+1*(2^8)+1*(2^7)+1*(2^6)+1*(2^4)+1*(2^1)+1*(2^0)

= 8192 + 4096 + 2048 + 256+ 128 + 64 + 16 + 2 + 1

=14803

Page 6: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

Decimal to Binary Conversion

Page 7: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

2.11 convert these decimal numbers to 8 bit 2’s complement binary numbers.

a) 102b) 64c) 33d) -125e) 127

Page 8: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

2.11.a --- Solution

• 102128 64 32 16 8 4 2 1

0 1 1 0 0 1 1 0

102

51 0

25 1

12 16 0

3 0

1 1

0 1

Page 9: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

2.11.d --- Solution • -125

Two’s complement:

10000010 (flipping the digits above)+ 1 (adding “1”) 10000011

128 64 32 16 8 4 2 1

0 1 1 1 1 1 0 1

Page 10: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

Decimal fractions to Binary

• (0.3125)10 = (?)2 0.3125 * 2 = 0.6250.625 * 2 = 1.250.25 * 2 = 0.50.5 * 2 = 1.0

(0.3125)10 = (0.0101)2

• (0.0101)2 = (0. 0*2-1+1*2-2+0*2-3+1*2-4)10

= (0. 0 + 0.25 + 0 + 0.0625)10

= (0.3125)10

Page 11: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

2.39 Write IEEE floating point representation of the following decimal

numbers?a) 3.75b) -55.359375c) 3.1415927d) 64,000

Page 12: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

2.39.b --- Solution

• -(55.359375)10 = -(110111.010111)2

• Normalizing the number -1.10111010111 . 25

• 1 10000100 10111010111000000000000

– The sign bit is 1, reflecting the fact that the number is a negative number

– The exponent: 5 = 132 – 127 =>10000100

Page 13: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

2.39.d --- Solution

• (64,000)10 = (1111101000000000)2

• Normalizing the number 1111101000000000 = 1.111101000000000 . 2 15

• 0 10001110 11110100000000000000000– The sign bit is 0, reflecting the fact that the

number is a positive number – The exponent is 15 = 142 – 127

Page 14: COMPSCI 210 Semester 1 - 2015 Tutorial 1. Binary to Decimal Conversion

ASCII Codes

• ASCII stands for American Standard Code For Information Interchange. – Each key on the keyboard is identified by its

unique ASCII code– When you type a key on the keyboard, the

corresponding eight-bit code is stored and made available to the computer

– Most keys are associated with more than one code, for example, h and H have two different codes