Professional Documents
Culture Documents
Module - 1
1
Numbers
• Each number system is associated with a base or radix
– The decimal number system is said to be of base or radix 10
• A number in base r contains r digits 0,1,2,...,r-1
– Decimal (Base 10): 0,1,2,3,4,5,6,7,8,9
• Numbers are usually expressed in positional notation
3
Numbers
4
Unsigned Binary Numbers
• The binary number system: Base-2
• Two digits: 0 and 1
• The digits in a binary number are called bits
5
Unsigned Binary Numbers
6
Unsigned Binary Numbers
• For a computer with the word size of 32-bit
- 4 data-bit unit – nibble (half byte)
- 8 data-bit unit - byte
- 16 data-bit unit – two bytes (half-word)
- 32 data-bit unit – word (four bytes)
- 64 data-bit unit – double-word
Powers of 2:
20 = 1 24 = 16 28 = 256
21 = 2 25 = 32 29 = 512
22 = 4 26 = 64 210 = 1024
23 = 8 27 = 128
7
Converting Binary to Decimal
• For example, here is 1101.01 in binary:
1 1 0 1 . 0 1 Bits
23 22 21 20 2-1 2-2 Weights (in base 10)
8 + 4 + 0 + 1 + 0 + 0.25 = 13.25
(1101.01)2 = (13.25)10
8
Converting Decimal to Binary
• To convert a decimal integer into binary, keep dividing by 2 until
the quotient is 0. Collect the remainders in reverse order
• To convert a fraction, keep multiplying the fractional part by 2
until it becomes 0. Collect the integer parts in forward order
• Example: 162.375:
• So, (162.375)10 = (10100010.011)2
10
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 Significan t Bit
1
2 3 r 1 610 = 1102
0
2 1 r 1 Most Significan t Bit
11
Dec → Binary : Example #1
Example:
Convert the decimal number 2610 into its binary equivalent.
12
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
13
Dec → Binary : Example #2
Example:
Convert the decimal number 4110 into its binary equivalent.
14
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 15
Dec → Binary : More Examples
a) 1310 = ?
b) 2210 = ?
c) 4310 = ?
d) 15810 = ?
16
Dec → Binary : More Examples
a) 1310 = ? 11012
b) 2210 = ? 101102
c) 4310 = ? 1010112
d) 15810 = ? 100111102
17
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
18
Binary → Dec : Example #1
Example:
Convert the binary number 100102 into its decimal equivalent.
19
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
20
Binary → Dec : Example #2
Example:
Convert the binary number 01101012 into its decimal equivalent.
21
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
22
Binary → Dec : More Examples
a) 0110 2 = ?
b) 11010 2 = ?
c) 0110101 2 = ?
d) 11010011 2 = ?
23
Binary → Dec : More Examples
a) 0110 2 = ? 6 10
b) 11010 2 = ? 26 10
c) 0110101 2 = ? 53 10
d) 11010011 2 = ? 211 10
24
Octal and Hexadecimal Numbers
• The octal number system: Base-8
• Eight digits: 0,1,2,3,4,5,6,7
(127.4)8 1 82 2 81 7 80 4 81 (87.5)10
25
Numbers with Different Bases
Decimal Binary Octal Hex
0 0000 0 0
1 0001 1 1
2 0010 2 2 You can convert between base-10
3 0011 3 3 base-8 and base-16 using techniques
4 0100 4 4
like the ones we just showed for
5 0101 5 5
converting between decimal and
6 0110 6 6
binary
7 0111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
26
Binary and Octal Conversions
• Converting from octal to binary: Replace each octal digit with its
equivalent 3-bit binary sequence
(110111011.001010)2
(673.12)8 = 6 7 3 . 1 2
= 110 111 011 . 001 010
10110100.0010112 = = 010 110 100 . 001 0112
= 2 6 4 . 1 38
• Converting from binary to octal: Make groups of 3 bits, starting from the
binary point. Add 0s to the ends of the number if needed. Convert each bit
group to its corresponding octal digit.
Octal Binary Octal Binary
0 000 4 100
1 001 5 101
2 010 6 110
27
3 011 7 111
Binary and Hex Conversions
• Converting from hex to binary: Replace each hex digit with its
equivalent 4-bit binary sequence
261.3516 = 2 6 1 . 3 516
= 0010 0110 0001 . 0011 01012
• Converting from binary to hex: Make groups of 4 bits, starting from the
binary point. Add 0s to the ends of the number if needed. Convert each bit
group to its corresponding hex digit
10110100.0010112 = 1011 0100 . 0010 11002
= B 4 . 2 C16
29
Binary Codes
• Decimal numbers are more natural to
humans. Binary numbers are natural to
computers.
• Binary codes are used in communication and
information systems
• Binary codes are used to represent letters,
numbers and punctuation marks.
• Binary codes are the basic building blocks of
modern digital computer techniques.
Types of Binary Codes
• BCD code
• Gray code
• Excess-3 code
• ASCII
• EBCDIC
The BCD Code
• BCD stands for Binary-Coded Decimal. The standard
binary code is used to convert decimal numbers into
equivalent binary numbers.
• A BCD number is a four-bit binary group that represents
one of the ten decimal digits 0 through 9.
Example:
Decimal number 4926 4 9 2 6
33
QUIZ
Decimal Number 8 7 1
QUIZ
Decimal Number 3 5 0
1 0 1 + 1 0 Binary 1 0 1 1 + 0 Binary
1 1 1 0 Gray 1 1 1 0 1 Gray
(10110)2 = (11101)Gray
Gray-to-Binary Conversion
Retain most significant bit.
From left to right, add each binary code bit generated to the
Gray code bit in the next position, discarding carries.
Example: Convert Gray code 11011 to binary.
1 1 0 1 1 Gray 1 1 0 1 1 Gray
+ +
1 0 0 1 Binary 1 0 0 1 0 Binary
(11011)Gray = (10010)2
The ASCII Code
• ASCII is an acronym for American Standard
Code for Information Interchange
• Represents numbers, letters, punctuation
marks and control characters
• Standard ASCII is a 7-bit code
• Extended ASCII (IBM ASCII), an 8-bit code, is
also very popular
• Extended ASCII adds graphics and math
symbols to code (total of 256 symbols)
QUIZ
1. A common 7-bit code used to represent
numbers, letters, punctuation marks,
and control characters is known by the
acronym __________. ASCII