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

L04-Number System Conversion

The document discusses how to convert numbers between decimal, binary, octal, and hexadecimal number systems. It explains the processes of successive division and weighted multiplication to convert between decimal and binary. It also covers adding, subtracting, and representing negative numbers in binary using ones' complement and twos' complement representations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

L04-Number System Conversion

The document discusses how to convert numbers between decimal, binary, octal, and hexadecimal number systems. It explains the processes of successive division and weighted multiplication to convert between decimal and binary. It also covers adding, subtracting, and representing negative numbers in binary using ones' complement and twos' complement representations.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

Number system- conversions

Introduction to Information and Communication


Technology

Air University Multan Campus


Instructor: Muhammad Yasir Khan
Decimal ‒to‒ Binary Conversion
The Process : Successive Division
a) Divide the Decimal Number by 2; the remainder is the LSB of Binary
Number .
b) If the quotation is zero, the conversion is complete; else repeat step (a)
using the quotation as the Decimal Number. The new remainder is the
next most significant bit of the Binary Number.

Example:
Convert the decimal number 610 into its binary equivalent.

3
2 6 r  0  Least Significant Bit
1
2 3 r 1  610 = 1102
0
2 1 r  1  Most Significant Bit
2
Dec → Binary : Example #1
Example:
Convert the decimal number 2610 into its binary equivalent.

3
Dec → Binary : Example #1
Example:
Convert the decimal number 2610 into its binary equivalent.

Solution:
13
2 26 r  0  LSB
6
2 13 r 1
3
2 6 r 0  2610 = 110102
1
2 3 r 1
0
2 1 r  1  MSB

4
Dec → Binary : Example #2
Example:
Convert the decimal number 4110 into its binary equivalent.

5
Dec → Binary : Example #2
Example:
Convert the decimal number 4110 into its binary equivalent.

Solution:
20
2 41 r  1  LSB
10
2 20 r 0
5
2 10 r 0  4110 = 1010012
2
2 5 r 1
1
2 2 r 0
0
2 1 r  1  MSB
6
Dec → Binary : More Examples
a) 1310 = ?

b) 2210 = ?

c) 4310 = ?

d) 15810 = ?

7
Dec → Binary : More Examples
a) 1310 = ? 11012

b) 2210 = ? 101102

c) 4310 = ? 1010112

d) 15810 = ? 100111102

8
Binary ‒to‒ Decimal Process
The Process : Weighted Multiplication
a) Multiply each bit of the Binary Number by it corresponding bit-
weighting factor (i.e. Bit-0→20=1; Bit-1→21=2; Bit-2→22=4; etc).
b) Sum up all the products in step (a) to get the Decimal Number.

Example:
Convert the decimal number 01102 into its decimal equivalent.

0 1 1 0
23 22 21 20
Bit-Weighting  0110 2 = 6 10
8 4 2 1 Factors

0 + 4 + 2 + 0 = 610

9
Binary → Dec : Example #1
Example:
Convert the binary number 100102 into its decimal equivalent.

10
Binary → Dec : Example #1
Example:
Convert the binary number 100102 into its decimal equivalent.

Solution:

1 0 0 1 0
24 23 22 21 20

16 8 4 2 1

16 + 0 + 0 + 2 + 0 = 1810

\100102 = 1810
11
Binary → Dec : Example #2
Example:
Convert the binary number 01101012 into its decimal
equivalent.

12
Binary → Dec : Example #2
Example:
Convert the binary number 01101012 into its decimal
equivalent.
Solution:

0 1 1 0 1 0 1
26 25 24 23 22 21 20

64 32 16 8 4 2 1

0 + 32 + 16 + 0 + 4 + 0 + 1 = 5310

\01101012 = 5310
13
Binary → Dec : More Examples
a) 0110 2 = ?

b) 11010 2 = ?

c) 0110101 2 = ?

d) 11010011 2 = ?

14
Binary → Dec : More Examples
a) 0110 2 = ? 6 10

b) 11010 2 = ? 26 10

c) 0110101 2 = ? 53 10

d) 11010011 2 = ? 211 10

15
Summary & Review
Base10 Successive
Division
Base2
DECIMAL BINARY
a) Divide the Decimal Number by 2; the remainder is the LSB of Binary
Number .
b) If the Quotient Zero, the conversion is complete; else repeat step (a) using
the Quotient as the Decimal Number. The new remainder is the next most
significant bit of the Binary Number.

Base2 Weighted
Multiplication
Base10
BINARY DECIMAL
a) Multiply each bit of the Binary Number by it corresponding bit-weighting
factor (i.e. Bit-0→20=1; Bit-1→21=2; Bit-2→22=4; etc).
b) Sum up all the products in step (a) to get the Decimal Number.
16
Converting numbers from other bases to their
decimal equivalents
• Binary 1001 (so r=2) : • Hexadecimal 12AC (so r=16):
• D = 1x20+0x21+0x22+1x23 • D = Cx160+Ax161+2x162+1x163
= 1+0+0+8 = 12+160+512+4096
=9 = 4780
• Octal 1767 (so r=8) :
• (A represents a decimal 10 and C
• D = 7x8 +6x8 +7x8 +1x8
0 1 2 3
represents a decimal 12)
= 7+48+448+512
= 1015

12/14/2023 18
Binary → hex/decimal/octal conversion
• Conversion from binary to octal/hex
• Binary: 10011110001
• Octal: 10 | 011 | 110 | 001=23618
• Hex: 100 | 1111 | 0001=4F116

• Conversion from binary to decimal


• 1012= 1×22 + 0×21 + 1×20 = 510
• 63.48 = 6×81 + 3×80 + 4×8–1 = 51.510
• A116= 10×161 + 1×160 = 16110
Decimal→ binary/octal/hex conversion

• Why does this work?


• N=5610=1110002
• Q=N/2=56/2=111000/2=11100 remainder 0

• Each successive divide liberates an LSB (least


significant bit)
(199834)10 = (110000110010011010)2 =
(30C9A)16

It’s your turn now.


Addition & Subtraction of Binary Numbers

1011 1011
+ 1010 – 0110
10101 0101
Number systems
• How do we write negative binary numbers?
• Historically: 3 approaches
• Sign-and-magnitude
• Ones-complement
• Twos-complement

• For all 3, the most-significant bit (MSB) is the sign digit


• 0 ≡ positive
• 1 ≡ negative

• twos-complement is the important one


• Simplifies arithmetic
• Used almost universally
Sign-and-magnitude
• The most-significant bit (MSB) is the sign digit
• 0 ≡ positive
• 1 ≡ negative

• The remaining bits are the number’s magnitude


• Problem 1: Two representations for zero
• 0 = 0000 and also –0 = 1000

• Problem 2: Arithmetic is cumbersome


Subtraction using 1’s Compliment
To subtract two binary values we use the standard method just like
decimals. BUT
• In 1’s compliment we take the complement of value that we want to
subtract and then perform addition.
• If at the end, a carry remains then we add that carry in the answer to
get the final result.
• Otherwise, we will again take 1’s complement of the result.
Example: 1’s Compliment
• (110101)2 – (100101)2
• Take 1’s complement of second value.
• (100101)’ = 011010
• Add this value in the first value
• 110101 + 011010 = 1 001111 We have a carry 1 here

• Add carry in the calculated result.


• 001111 + 000001 = 010000
Example: (101011)2 – (111001)2 Subtract using
1’s complement.
Subtraction using 2’s Complement
• For 2’s compliment
• First find the 1’s compliment of the number
• Add 1 in the answer

• Calculated value will be the 2’s complement of the binary value.


• If there is carry value drop it.
• If there is no carry left again take the 2’s compliment and final answer
will be negative value.
Example
• (110110)2 – (010110)2
• Step 1: Invert the 2nd value (Take 1’s complement)
• (010110)’2 = (101001)2
• Step 2: Add 1 in the result
• (101001)2 + (000001) = 101010
• Discard the carry as we are taking 2’s complement
• Add the calculated value in 1st value.
• (110110)2 + (101010)2 = (100000)2
Subtraction by 2’s Complement
• (10110)2 – (11010)2
• = -(00100)2 Answer
12/14/2023 31
Number Overflow
• Overflow occurs when the value that we compute cannot fit into the
number of bits we have allocated for the result.
• For example, if each value is stored using eight bits, adding 127 to 3
would overflow:
• 01111111
• + 00000011
• ---------------
• 10000010

12/14/2023 32
Number Overflow
• 100000010 in our scheme represents 126, not +130. If, however, we
were not representing negative numbers, the result would be correct.

12/14/2023 33
Code for Letters and Symbols
• Computers use a standard binary code to represents letters of the alphabet,
numerals, punctuation marks and other special characters.
• The code is called ASCII (pronounced “askey”) which stands for “American
Standard Code for Information Interchange.”
• There are 256 code combinations.

12/14/2023 34
Sources
• [1] http://en.wikipedia.org/wiki/Numeral_systems
• [2] http://www.mathsisfun.com/definitions/base-numbers-.html
• [3] http://atrevida.comprenica.com/atrtut01.html
• [4] http://www.mindspring.com/~jimvb/binary.htm

12/14/2023 35

You might also like