0% found this document useful (0 votes)
7 views24 pages

Week 01 02

computer system design-2

Uploaded by

AstaBasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views24 pages

Week 01 02

computer system design-2

Uploaded by

AstaBasu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Carnegie Mellon

4
Number Systems
Decimal Numbers

Binary Numbers

11012 =
537410 =
1's column 1's column
10's column 2's column
100's column 4's column
 1000's column 8's column


Carnegie Mellon

Number Systems
 Decimal Numbers
1000's column

10's column
1's column
100's column

537410 = 5 × 103 + 3 × 102 + 7 × 101 + 4 × 100


five three seven four
thousands hundreds tens ones

 Binary Numbers
8's column

2's column
1's column
4's column

11012 = 1 × 23 + 1 × 22 + 0 × 21 + 1 × 20 = 1310
one one no one
eight four two one

5
Carnegie Mellon

Powers of two
20 = 28 =
21 = 29 =
22 = 210 =
23 = 211 =
24 = 212 =
25 = 213 =
26 = 214 =
27 = 215 =

6
Carnegie Mellon

Powers of two
20 = 1 28 = 256
21 = 2 29 = 512
22 = 4 210 = 1024
23 = 8 211 = 2048
24 = 16 212 = 4096
25 = 32 213 = 8192
26 = 64 214 = 16384
27 = 128 215 = 32768

Handy to memorize up to 215


7
Carnegie Mellon

Binary to Decimal Conversion


 Convert 100112 to decimal

8
Carnegie Mellon

Binary to Decimal Conversion


 Convert 100112 to decimal

24 × 1 + 23 × 0 + 22 × 0 + 21 × 1 + 20 × 1 =

9
Carnegie Mellon

Binary to Decimal Conversion


 Convert 100112 to decimal

24 × 1 + 23 × 0 + 22 × 0 + 21 × 1 + 20 × 1 =

16 × 1 + 8 × 0 + 4 × 0 + 2 × 1 + 1 × 1 =

16 + 0 + 0 + 2 + 1 = 1910

10
Carnegie Mellon

Decimal to Binary Conversion


 Convert 4710 to binary

11
Carnegie Mellon

Decimal to Binary Conversion


 Convert 4710 to binary
 Start with 26 = 64 is 64 ≤ 47 ? no do nothing
 Now 25 = 32

12
Carnegie Mellon

Decimal to Binary Conversion


 Convert 4710 to binary
 Start with 26 = 64 is 64 ≤ 47 ? no do nothing
 Now 25 = 32 is 32 ≤ 47 ? yes subtract 47 – 32 =15
 Now 24= 16 is 16 ≤ 15 ? no do nothing
 Now 23= 8 is 8 ≤ 15 ? yes subtract 15 – 8 = 7
 Now 22= 4 is 4 ≤ 7 ? yes subtract 7-4 = 3
 Now 21= 2 is 2 ≤ 3 ? yes subtract 3-2 =1
 Now 20= 1 is 1 ≤ 1 ? yes we are done

13
Carnegie Mellon

Decimal to binary conversion


 Convert 4710 to binary
 Start with 26 = 64 is 64 ≤ 47 ? no 0 do nothing
 Now 25 = 32 is 32 ≤ 47 ? yes 1 subtract 47 – 32 =15
 Now 24= 16 is 16 ≤ 15 ? no 0 do nothing
 Now 23= 8 is 8 ≤ 15 ? yes 1 subtract 15 – 8 = 7
 Now 22= 4 is 4 ≤ 7 ? yes 1 subtract 7-4 = 3
 Now 21= 2 is 2 ≤ 3 ? yes 1 subtract 3-2 =1
 Now 20= 1 is 1 ≤ 1 ? yes 1 we are done

 Result is 01011112

14
Carnegie Mellon

Binary Values and Range


 N-digit decimal number
 How many values? 10N
 Range? [0, 10N - 1]
 Example: 3-digit decimal number
 103 = 1000 possible values
 Range: [0, 999]

 N-bit binary number


 How many values? 2N
 Range: [0, 2N - 1]
 Example: 3-digit binary number
 23 = 8 possible values
 Range: [0, 7] = [0002 to 1112]

15
Carnegie Mellon

Hexadecimal (Base-16) Numbers


Decimal Hexadecimal Binary
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Carnegie Mellon

Hexadecimal (Base-16) Numbers


Decimal Hexadecimal Binary
0 0 0000
1 1 0001
2 2 0010
3 3 0011
4 4 0100
5 5 0101
6 6 0110
7 7 0111
8 8 1000
9 9 1001
10 A 1010
11 B 1011
12 C 1100
13 D 1101
14 E 1110
15 F 1111
17
Carnegie Mellon

Hexadecimal Numbers
 Binary numbers can be pretty long.

 A neat trick is to use base 16

 How many binary digits represent a hexadecimal digit?


4 (since 24 = 16)

 Example 32 bit number:


0101 1101 0111 0001 1001 1111 1010 0110

18
Carnegie Mellon

Hexadecimal Numbers
 Binary numbers can be pretty long.

 A neat trick is to use base 16

 How many binary digits represent a hexadecimal digit?


4 (since 24 = 16)

 Example 32 bit number:


0101 1101 0111 0001 1001 1111 1010 0110
5 D 7 1 9 F A 6

19
Carnegie Mellon

Hexadecimal Numbers
 Binary numbers can be pretty long.

 A neat trick is to use base 16

 How many binary digits represent a hexadecimal digit?


4 (since 24 = 16)

 Example 32 bit number:


0101 1101 0111 0001 1001 1111 1010 0110
5 D 7 1 9 F A 6

 The other way is just as simple


C E 2 8 3 5 4 B
20
Carnegie Mellon

Hexadecimal Numbers
 Binary numbers can be pretty long.

 A neat trick is to use base 16

 How many binary digits represent a hexadecimal digit?


4 (since 24 = 16)

 Example 32 bit number:


0101 1101 0111 0001 1001 1111 1010 0110
5 D 7 1 9 F A 6

 The other way is just as simple


C E 2 8 3 5 4 B
1100 1110 0010 1000 0011 0101 0100 1011 21
Carnegie Mellon

Hexadecimal to Decimal Conversion


 Convert 4AF16 (or 0x4AF) to decimal

22
Carnegie Mellon

Hexadecimal to decimal conversion


 Convert 4AF16 (or 0x4AF) to decimal

162 × 4 + 161 ×A + 160 × F =

256 × 4 + 16 × 10 + 1 × 15 =

1024 + 160 + 15 = 119910

23
Carnegie Mellon

Bits, Bytes, Nibbles…

10010110
most least
significant significant
bit bit

byte

10010110
nibble

CEBF9AD7
most least
significant significant
byte byte

24
Carnegie Mellon

Powers of Two
 210 = 1 kilo ≈ 1000 (1024)

 220 = 1 mega ≈ 1 million (1,048,576)

 230 = 1 giga ≈ 1 billion (1,073,741,824)

25
Carnegie Mellon

Powers of Two (SI Compatible)


 210 = 1 kibi ≈ 1000 (1024)

 220 = 1 mebi ≈ 1 million (1,048,576)

 230 = 1 gibi ≈ 1 billion (1,073,741,824)

26
Carnegie Mellon

Estimating Powers of Two


 What is the value of 224?

 How many values can a 32-bit variable


represent?

27

You might also like