0% found this document useful (0 votes)
23 views

Lecture 02

Decimal, binary, octal, and hexadecimal are common number systems. Each system uses a different base and set of digits. Numbers can be converted between these systems by understanding their place value representations.

Uploaded by

Anonymous Here
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Lecture 02

Decimal, binary, octal, and hexadecimal are common number systems. Each system uses a different base and set of digits. Numbers can be converted between these systems by understanding their place value representations.

Uploaded by

Anonymous Here
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 39

Decimal Numbers

The position of each digit in a weighted number system is


assigned a weight based on the base or radix of the system.
The radix of decimal numbers is ten, because only ten
symbols (0 through 9) are used to represent any number.

The column weights of decimal numbers are powers


of ten that increase from right to left beginning with 100 =1:
…105 104 103 102 101 100.

For fractional decimal numbers, the column weights


are negative powers of ten that decrease from left to right:

102 101 100. 10-1 10-2 10-3 10-4 …


1
Decimal Numbers

Decimal numbers can be expressed as the sum of the


products of each digit times the column value for that digit.
Thus, the number 9240 can be expressed as
(9 x 103) + (2 x 102) + (4 x 101) + (0 x 100)
or
9 x 1,000 + 2 x 100 + 4 x 10 + 0 x 1

Express the number 480.52 as the sum of values of each


digit.

480.52 = (4 x 102) + (8 x 101) + (0 x 100) + (5 x 10-1) +(2 x 10-2)


2
Binary Numbers

For digital systems, the binary number system is used.


Binary has a radix of two and uses the digits 0 and 1 to
represent quantities.

The column weights of binary numbers are powers of


two that increase from right to left beginning with 20 =1:

…25 24 23 22 21 20.

For fractional binary numbers, the column weights


are negative powers of two that decrease from left to right:

22 21 20. 2-1 2-2 2-3 2-4 …


3
Binary to Decimal Conversions

The decimal equivalent of a binary number can be


determined by adding the column values of all of the bits
that are 1 and discarding all of the bits that are 0.

Convert the binary number 100101.01 to decimal.

Start by writing the column weights; then add the


weights that correspond to each 1 in the number.
25 24 23 22 21 20. 2-1 2-2
32 16 8 4 2 1 . ½ ¼
1 0 0 1 0 1. 0 1
32 +4 +1 +¼ = 37¼

4
Decimal(integer) to Binary Conversions

You can convert a decimal whole number to binary by


reversing the procedure. Write the decimal weight of each
column and place 1’s in the columns that sum to the decimal
number.

Convert the decimal number 49 to binary.

The column weights double in each position to the


right. Write down column weights until the last
number is larger than the one you want to convert.

26 2 5 2 4 2 3 2 2 21 2 0.
64 32 16 8 4 2 1.
0 1 1 0 0 0 1.

5
Decimal fraction to Binary Conversions

You can convert a decimal fraction to binary by repeatedly


multiplying the fractional results of successive
multiplications by 2. The carries form the binary number.

Convert the decimal fraction 0.188 to binary by


repeatedly multiplying the fractional results by 2.

MSB
0.188 x 2 = 0.376 carry = 0
0.376 x 2 = 0.752 carry = 0
0.752 x 2 = 1.504 carry = 1
0.504 x 2 = 1.008 carry = 1
0.008 x 2 = 0.016 carry = 0
Answer = .00110 (for five significant digits)
6
Hexadecimal Numbers
Decimal Hexadecimal Binary
0 0 0000
Hexadecimal uses sixteen characters to 1 1 0001
represent numbers: the numbers 0 2 2 0010
through 9 and the alphabetic characters 3 3 0011
A through F. 4 4 0100
5 5 0101
6 6 0110
Large binary number can easily 7 7 0111
be converted to hexadecimal by 8 8 1000
grouping bits 4 at a time and writing 9 9 1001
the equivalent hexadecimal character. 10 A 1010
11 B 1011
Express 1001 0110 0000 11102 in 12 C 1100
hexadecimal: 13 D 1101
Group the binary number by 4-bits 14 E 1110
starting from the right. Thus, 960E 15 F 1111

7
Hexadecimal Numbers
Decimal Hexadecimal Binary
0 0 0000
Hexadecimal is a weighted number
1 1 0001
system. The column weights are 2 2 0010
powers of 16, which increase from 3 3 0011
right to left. 4 4 0100
5 5 0101
6 6 0110
{
163 162 161 160.
Column weights 4096 256 16 1 .
7
8
7
8
0111
1000
9 9 1001
Express 1A2F16 in decimal. 10 A 1010
11 B 1011
Start by writing the column weights:
12 C 1100
4096 256 16 1
13 D 1101
1 A 2 F16
14 E 1110
1(4096) + 10(256) +2(16) +15(1) = 670310 15 F 1111

8
Octal Numbers
Decimal Octal Binary
0 0 0000
Octal uses eight characters the numbers
1 1 0001
0 through 7 to represent numbers. 2 2 0010
There is no 8 or 9 character in octal. 3 3 0011
4 4 0100
5 5 0101
Binary number can easily be
6 6 0110
converted to octal by grouping bits 3 at 7 7 0111
a time and writing the equivalent octal 8 10 1000
character for each group. 9 11 1001
10 12 1010
Express 1 001 011 000 001 1102 in
11 13 1011
octal: 12 14 1100
Group the binary number by 3-bits 13 15 1101
starting from the right. Thus, 1130168 14 16 1110
15 17 1111

9
Octal Numbers
Decimal Octal Binary

Octal is also a weighted number 0 0 0000


1 1 0001
system. The column weights are 2 2 0010
powers of 8, which increase from right 3 3 0011
to left. 4 4 0100
5 5 0101
6 6 0110
{
83 8 2 8 1 8 0 .
Column weights 512 64 8 1 .
7
8
7
10
0111
1000
9 11 1001
Express 37028 in decimal. 10 12 1010
11 13 1011
Start by writing the column weights:
12 14 1100
512 64 8 1
13 15 1101
3 7 0 28
14 16 1110
3(512) + 7(64) +0(8) +2(1) = 198610 15 17 1111

10
Binary ↔ Octal ↔ Hex Shortcut
Because binary, octal, and hex number systems are all powers of two
(which is the reason we use them) there is a relationship that we can
exploit to make conversion easier.
1 0 1 1 0 1 0 2 = 132 8 = 5A H
To convert directly between binary and octal, group the binary bits into
sets of 3 (because 23 = 8). You may need to pad with leading zeros.
0 0 1 0 1 1 0 1 0 2= 1 3 28

1 3 2 001 011 010


To convert directly between binary and hexadecimal number systems,
group the binary bits into sets of 4 (because 24 = 16). You may need to
pad with leading zeros.
0 1 0 1 1 0 1 0 2= 5 A 16

5 A 0101 1 010

11
Example: Binary ↔ Octal ↔ Hex
Example:
Using the shortcut technique, convert the hexadecimal number A6 16
into its binary and octal equivalent. Use your calculator to check your
answers.

12
Example: Binary ↔ Octal ↔ Hex
Example:
Using the shortcut technique, convert the hexadecimal number A6 16
into its binary & octal equivalent. Use your calculator to check your
answers.
Solution:
First convert the hexadecimal number into binary by expanding the
hexadecimal digits into binary groups of (4).
A 6 16
 A616 = 101001102
1010 0110
Convert the binary number into octal by grouping the binary bits into
groups of (3).
010100110
 101001102 = 2468
2 4 6
13
Signed Number Representation
• Signed Numbers in Base-2
• Represented (usually) by
• Sign-Magnitude Method
• 1’s Complement Method
• 2’s Complement Method

Computer Science & Information Technology Department


14
Sir Syed University of Engg. & Tech . Lecture by: Mr. Shakir Karim
Signed Numbers
• Sign-Magnitude Method

Computer Science & Information Technology Department


15
Sir Syed University of Engg. & Tech . Lecture by: Mr. Shakir Karim
Signed Numbers (cont…/2)
• Sign-Magnitude Method

Computer Science & Information Technology Department


16
Sir Syed University of Engg. & Tech . Lecture by: Mr. Shakir Karim
Range of Signed Integers
The range of signed integers is given as:
-(2(n-1)-1) to +(2(n-1) -1)
For example: if we have 4 bits to represent a signed binary number,
(1-bit for the Sign bit and 3-bits for the Magnitude bits), then the
actual range of numbers we can represent in sign-magnitude notation
would be: -2(4-1) – 1 to +2(4-1) – 1
-2(3) – 1 to +2(3) – 1
-7 to +7

17
Range of Signed Integers
• Whereas before, the range of an unsigned 4-bit binary number would
have been from 0 to 15, or 0 to F in hexadecimal.
• We now have a reduced range of -7 to +7. Thus an unsigned binary
number does not have a single sign-bit, and therefore can have a
larger binary range as the most significant bit (MSB) is just an extra
bit or digit rather than a used sign bit.

18
Disadvantage of Signed Magnitude Method
• The disadvantage here is that whereas before we had a full
range n-bit unsigned binary number, we now have an n-1
bit signed binary number giving a reduced range of digits
from
• Another disadvantage here of the sign-magnitude form is
that we can have a positive result for zero, +0 or 00002, and a
negative result for zero, -0 or 10002. Both are valid but which
one is correct.

19
Example
Convert the following decimal values into signed binary numbers using
the sign-magnitude format
-1510 as a 6-bit number ⇒ 1011112

+2310 as a 6-bit number ⇒ 0101112

-5610 as a 8-bit number ⇒ 101110002

+8510 as a 8-bit number ⇒ 010101012

-12710 as a 8-bit number ⇒ 111111112

20
Signed Numbers
• Sign-Magnitude Method

21
Signed Numbers (cont…/3)
• 1’s Complement Method

22
Signed Numbers (cont…/4)

23
Signed Numbers (cont…/4)

24
Signed Numbers (cont…/4)

25
Signed Numbers (cont…/4)

26
Signed Numbers (cont…/4)

27
Signed Numbers (cont…/4)

28
Signed Numbers (cont…/4)

29
Signed Numbers (cont…/4)

30
Signed Numbers (cont…/5)
The Decimal Value of Signed Number

31
Signed Numbers (cont…/5)
The Decimal Value of Signed Number

32
Signed Numbers (cont…/5)
The Decimal Value of Signed Number

33
Signed Numbers (cont…/5)
The Decimal Value of Signed Number

34
Signed Numbers (cont…/5)
The Decimal Value of Signed Number

35
Signed Numbers (cont…/5)
The Decimal Value of Signed Number

36
Signed Numbers (cont…/6)
The Decimal Value of Signed Number

37
Signed Numbers (cont…/6)
The Decimal Value of Signed Number

38
Signed Numbers (cont…/6)
The Decimal Value of Signed Number

39

You might also like