Week 7

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 50

Number System

Bits, Bytes

Unit Symbol Number of Bytes


kilobyte KB 210 = 1024
20
megabyte MB 2 (over 1 million)
gigabyte GB 230 (over 1 billion)
40
terabyte TB 2 (over 1 trillion)
Bit Transformation
1 bit 2 bits 3 bits 4 bits
0 00 000 0000 1000
1 01 001 0001 1001
10 010 0010 1010
11 011 0011 1011
100 0100 1100
101 0101 1101
110 0110 1110
111 0111 1111

Each additional bit doubles the number of possible permutations


Number Systems

• The on and off states of the capacitors


in RAM can be thought of as the values
1 and 0, respectively.
• Therefore, thinking about how
information is stored in RAM requires
knowledge of the binary (base 2)
number system.
• Let’s review the decimal (base 10)
number system first.
Converting From Decimal to
Binary
• Make a list of the binary place values up
to the number being converted.
• Perform successive divisions by 2,
placing the remainder of 0 or 1 in each
of the positions from right to left.
• Continue until the quotient is zero.
Example: 4210

25 24 23 22 21 20
32 16 8 4 2 1
1 0 1 0 1 0
The Decimal Number System
(con’t)
• The decimal number system is also known
as base 10.
• The values of the positions are calculated
by taking 10 to some power.
• Why is the base 10 for decimal numbers?
– Because we use 10 digits, the digits 0 through
9.
Converting From Decimal to Binary
Practice conversions:
Decimal Binary
59
82
175
The Decimal Number System
• The decimal number system is a positional
number system.
• Example:

 5 6 2 1 1 X 100 = 1
 103 102 101 100 2 X 101 = 20
 6 X 102 = 600
 5 X 103 = 5000
The Binary Number System
• The binary number system is also known
as base 2. The values of the positions are
calculated by taking 2 to some power.
• Why is the base 2 for binary numbers?
– Because we use 2 digits, the digits 0 and 1.
The Binary Number System
(con’t)
• The binary number system is also a
positional numbering system.
• Instead of using ten digits, 0 - 9, the
binary system uses only two digits, 0
and 1.
• Example of a binary number and the
values of the positions:
 1 0 0 1 1 0 1
 26 25 24 23 22 21 20
Converting from Binary to
Decimal
 1 0 0 1 1 0 1 1 X 20 = 1
 26 25 24 23 22 21 20 0 X 21 = 0
 1 X 22 = 4
 20 = 1 24 = 16 1 X 23 = 8
 21 = 2 25 = 32 0 X 24 = 0
 22 = 4 26 = 64 0 X 25 = 0
 23 = 8 1 X 26 = 64
7710
Another Example
– Example: Convert the binary whole number
1101101 to decimal.
Solution: Weight: 26 25 24 23 22 21 20
Binary number: 1 1 0 1 1 0 1
1101101 = 26 + 25 + 23 + 22 + 20
= 64 + 32 + 8 + 4 + 1 = 109
Fractional binary number
– Example: Convert the fractional binary
number 0.1011 to decimal.
Solution: Weight:0 2-1 2-2 2-3 2-4
Binary number: 0 . 1 0 1 1
0.1011 = 2-1 + 2-3 + 2-4
= 0.5 + 0.125 +0.0625 = 0.6875
Binary Arithmetic
• Binary Addition
• Binary Subtraction
• Binary Multiplication
• Binary Division
Binary Addition
• The four basic rules for adding binary digits
(bits) are as follows:
0+0=0 Sum of 0 with a carry of 0
0+1=1 Sum of 1 with a carry of 0
1+0=1 Sum of 1 with a carry of 0
1 + 1 = 10 Sum of 0 with a carry of 1
Binary Addition (contd.)
• When there is a carry of 1, you have a situation in
which three bits are being added ( a bit in each of
the two numbers and a carry bit).
• 1 + 0 + 0 =01 Sum of 1 with a carry of 0
• 1 + 1 + 0 =10 Sum of 0 with a carry of 1
• 1 + 0 + 1 =10 Sum of 1 with a carry of 1
• 1 + 1 + 1 =11 Sum of 1 with a carry of 1
Binary Addition (contd.)
• Example: Add the following binary numbers.
11 + 11
Solution : 1 1
+11
110
Binary Subtraction
• The four basic rules for subtracting binary digits (bits) are as
follows:
0-0=0
1-1=0
1-0=1
10 - 1 = 0 0 - 1 with a borrow of 1
• When subtracting numbers, you sometimes have to borrow
from the next column to the left.
• A borrow is required in binary only when you try to
subtract a 1 from a 0. In this case, when a 1 is borrowed
from the next column to the left, a 10 is created in the
column being subtracted and the last of the four rules must
be applied.
Binary Subtraction (contd.)
• Example: Perform the following binary
subtractions. 11 - 01
Solution : 1 1
-01
10
Binary Multiplication
• The four basic rules for multiplying binary digits (bits) are
as follows:
0x0=0
0x1=0
1x0=0
1x1=1
• Multiplication is performed with binary numbers in the
same manner as with decimal numbers.
• It involves forming partial products, shifting each
successive partial product left one place, and then adding all
the partial products.
Binary Multiplication (contd.)
• Example: Perform the following binary
multiplication. 11 x 01
Solution : 1 1
x11
11
+ 11 .
1001
Binary Division
• Binary division follows the same procedure
as division in decimal.
• Example : Perform the following binary
division: 110 / 11
Solution: 10

11 110

11

000
Converting from Binary to
Decimal
• Practice conversions:
• Binary Decimal
• 11101
• 1010101
• 100111
Working with Large Numbers
• 0101000010100111 = ?

• Humans can’t work well with binary


numbers; there are too many digits to deal
with.
• Memory addresses and other data can be
quite large. Therefore, we sometimes use
the hexadecimal number system.
Other popular number systems

• Octal
base = 8
8 symbols (0,1,2,3,4,5,6,7)

• Hexadecimal
base = 16
16 symbols (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
The Hexadecimal Number
System
• The hexadecimal number system is also
known as base 16. The values of the
positions are calculated by taking 16 to
some power.
• Why is the base 16 for hexadecimal
numbers ?
– Because we use 16 symbols, the digits
0 through 9 and the letters A through F.
Binary-to-Hexadecimal Conversion
• Break the binary number into 4-bit groups,
starting at the right-most bit and replace
each 4-bit group with the equivalent
hexadecimal symbol.

29
Example
• Convert the following binary number to
hexadecimal:
1100101001010111
Solution: 1100101001010111

C A 5 7 CA5716

30
Hexadecimal to Binary Conversion
• To convert from a hexadecimal number to a
binary number, replace each hexadecimal
symbol with the appropriate four bits.

31
Example
• Determine the binary numbers for the
following hexadecimal number:
10A416
Solution: 1 0 A 4

1 0000 1010 0100

32
Hexadecimal to Decimal Conversion
• One way to find the decimal equivalent of a
hexadecimal number is to first convert the
hexadecimal number to binary and then
convert from binary to decimal.

33
Example
• Convert the following hexadecimal numbers
to decimal. 1C16

Solution: 1 C
0001 1100 24 + 23 + 22 =16 + 8 + 4 = 2810

34
Hexadecimal to Decimal Conversion
(contd.)
• Another way to convert a hexadecimal number to
its decimal equivalent is to multiply the decimal
value of each hexadecimal digit by its weight and
then take the sum of these products. The weight of
a hexadecimal number are increasing powers of 16
(from right to left). For a 4-digit hexadecimal
number, the weights are: 163 162 161 160
4096 256 16 1

35
Example
• Convert the following hexadecimal numbers
to decimal. E516

Solution: E516 = (E x 16) + ( 5 x 1)


= (14 x 16) + (5 x 1)
= 224 +5
= 22910

36
Decimal-to-Hexadecimal Conversion
• Repeated division of a decimal number by 16
will produce the equivalent hexadecimal
number, formed by the remainders of the
divisions.
• The first remainder produced is the least
significant digit (LSD).

37
Hexadecimal Addition
• Addition can be done directly with
hexadecimal numbers by remembering that
the hexadecimal digits 0 through 9 are
equivalent to decimal digits 0 through 9 and
that hexadecimal digits A through F are
equivalent to decimal numbers 10 through
15.

38
Example
• Add the following hexadecimal number.
2316 +1616
Solution: 2316
+ 1616
3916

39
The Hexadecimal Number System
(cont.)
Binary Decimal Hexadecimal Binary Decimal Hexadecimal
0 0 0 1010 10 A
1 1 1 1011 11 B
10 2 2 1100 12 C
11 3 3 1101 13 D
100 4 4 1110 14 E
101 5 5 1111 15 F
110 6 6
111 7 7
1000 8 8
1001 9 9
The Hexadecimal Number
System
• Example of a hexadecimal number and
the values of the positions:
 3 C 8 B 0 5 1
 166 165 164 163 162 161 160
Octal Numbers
• The octal number system is composed of
eight digits, which are:
–0,1,2,3,4,5,6,7
• To count above 7:
– 10 , 11 , 12 , 13 , 14 , 15 , 16 , 17 , 20 , 21

42
Octal-to-Decimal Conversion
• The octal number system has a base of eight,
each successive digit position is an increasing
power of eight, beginning in the right-most
column with 80.
• The evaluation of an octal number in terms
of its decimal equivalent is accomplished by
multiplying each digit by its weight and
summing the products.

43
Octal-to-Decimal Conversion
(contd.)
• Example: Convert octal number 23748 to
decimal number.
Weight : 83 82 81 80
Octal number : 2 3 7 4
23748 = ( 2 x 83) + ( 3 x 82) + ( 7 x 81) + ( 4 x 80)
= ( 2 x 512) + ( 3 x 64) + ( 7 x 8) + ( 4 x 1)
= 1024 + 192 + 56 + 4
= 127610

44
Octal-to-Binary Conversion
• Replace each octal digit by a 3-bit binary
number.
• Example: Convert the following octal
numbers to binary: 138
Solution: 1 3

001 011

45
Binary-to-Octal Conversion
• Conversion of a binary number to an octal
number is the reverse of the octal-to-binary
conversion.
• The procedure is as follows:
– Start with the right-most group of three bits and
moving from right to left, convert each 3-bit
group to the equivalent octal digit.
– If there are not three bits available for the left-
most group, add either one or two zeros to make
a complete group.

46
Example
• Convert the following binary number to
octal: 110101
Solution: 110101
6 5 = 658

47
Example of Equivalent
Numbers
• Binary: 111111000000101000110

Octal: 07700506

• Decimal: 2064710

• Hexadecimal: 0x1F8146

• Notice how the number of digits gets


smaller as the base increases.
Assignment #1
• (67)10 ,(77)10,(1456)10 convert into binary
number
• (1000111)2,(001010100)2,(111110011111)2
10010001, 10.111, covert into decimal
number
Assignment # 2 (contd.)
6. Perform the following binary additions:
a. 1101 + 1010 b. 10111 + 01101
7. Perform the following binary
subtractions:
a. 1101 – 0100 b. 1001 - 0111
8. Perform the indicated binary operations:
a. 110 x 111 b. 1100 / 011

You might also like