number system
DESCRIPTION
Number System. ITE102 – Computer Programming (C++). Topics. 1-1 Introduction to Binary 1-2 Understanding Number System 1-3 Conversion of Number System. Learning Objects. After completing this module that student will be able to : Distinguish the different number systems - PowerPoint PPT PresentationTRANSCRIPT
Number SystemITE102 – Computer Programming (C++)
Topics
• 1-1 Introduction to Binary• 1-2 Understanding Number System• 1-3 Conversion of Number System
Number SystemsNumber Systems 2
Learning Objects
• After completing this module that student will be able to : – Distinguish the different number systems – Convert from one number system to another
Number SystemsNumber Systems 3
Introduction to data conversion
• The study of binary system will help us gain better understanding of how computers perform computation.
Number SystemsNumber Systems 4
Understanding Number System
• The radix, or base, of a number system is the total number of unique symbols available in that system.
• The largest valued symbol always has a magnitude of one less than the radix.
Number SystemsNumber Systems 5
Decimal Numbers
• Decimal notation is the writing of numbers in the base-ten numeral system, which uses various symbols (called digits) for ten distinct values (0, 1, 2, 3, 4, 5, 6, 7, 8 and 9) to represent numbers.
• These digits are often used with a decimal separator which indicates the start of a fractional part, and with one of the sign symbols + (plus) or − (minus) to indicate sign.
Number SystemsNumber Systems 6
Decimal Numbers (cont.)
• The decimal system is a positional numeral system; it has positions for units, tens, hundreds, etc.
• The position of each digit conveys the multiplier (a power of ten) to be used with that digit—each position has a value ten times that of the position to its right.
Number SystemsNumber Systems 7
Binary Numbers(studied by Gottfried Leibniz in 1679)
• The binary system works in exactly the same way, except that its place value is based on the number two.
• In the binary system, we have the one's place, the two's place, the four's place, the eight's place, the sixteen's place, and so on.
• Each place in the number represents two times (2X's) the place to its right.
• Binary number system has a base, or radix, of 2. Binary numbers are composed of two symbols: 0 and 1.
Number SystemsNumber Systems 8
Binary Numbers (cont.)
Decimal Binary
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
9Number Systems
1 0 1 08 4 2 1
Considering the digits that has a value of 1 and adding it number marker on the top of each digits
8 + 2 = 10
Octal Numbers
• The octal number system has a base, or radix, of 8. Octal numbers are composed of eight symbols: 0, 1, 2, 3, 4, 5, 6, and 7.
Number SystemsNumber Systems 10
Hexadecimal Numbers
• The hexadecimal number system has a base, or radix, of 16. Hexadecimal numbers are composed of sixteen symbols: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.
• Symbols A to F correspond to decimal numbers 10 to 15.
Number SystemsNumber Systems 11
Conversion of the Number System
• Binary to Decimal , Octal, Hexadecimal• Decimal to Binary, Octal, Hexadecimal• Octal to Decimal, Binary, Hexadecimal• Hexadecimal to Binary, Octal, Decimal
Number SystemsNumber Systems 12
Binary to Decimal• Remember that Binary numbers are based on the radix
of 2 while Decimal numbers are based on the radix of 10.• Remember also that binary will only be represented in 1s
and 0s.• Steps in converting Binary to Decimal:
– Place a number marker on the top of the given digits, starting from 0 up the last given digits—starting from the right to determine the exponent to use.
– Consider all the 1s in the given digits and multiply it with the base number of the given digits (which is base 2) and raised it with power of the number corresponded in the number marker you placed on the top of the given digits.
Number SystemsNumber Systems 13
Example: Binary to Decimal
1010102 = ?10
= 101010
= 1*25 + 1*23 + 1*21
= 32 + 8 + 2
= 4210
Number SystemsNumber Systems 14
5 4 3 2 1 0
Place the number marker on the top of the given digits, starting from the right, starting from 0 up to the last given digit on the left.
Example: Binary to Decimal
101.012 = ?10
= 101.01
= 1*22 + 1*20 + 1*2-2
= 4 + 1 + 0.25
= 5.2510
15
2 1 0 -1 -2
If dealing with fraction in binary the marker will start at the right side of the decimal point and starting with the -1 up to the last given digit.
1*2-2 will be converted into 1*2½ which results into 0.25 because you will be dividing
1 / 4 which comes from 1*2½
Binary to Octal• Since one octal digit is equivalent to three binary digits,
just group three binary digits, starting from the least significant bit (right side).
• Append 0 to the most significant bit (left side), if the grouping does not have enough to form three binary digits.
• In short, you must complete the grouping of three digits. • If you will be having a fraction (decimal point), append 0
to the least most significant bit (right side) of the given digits to complete the grouping of three bits.
Number SystemsNumber Systems 16
Binary to Octal (cont.)• Steps in converting Binary to Octal:
– Group the given digits in three starting from the right side.
– If the grouping is not complete, place 0 to complete the grouping.
– Once you have grouped it into three digits, you starting converting the binary digits into decimal values following the concepts of binary digits (4, 2, 1) starting from the right.
Number SystemsNumber Systems 17
Example: Binary to Octal
11010102 = ?8
= 001 101 010
= 001 101 010
= 1 5 28
= 1528
Number SystemsNumber Systems 18
1st group2nd group3rd group
4 2 14 2 14 2 1
Add 0 to the left, to complete the grouping
Simply add all the number markers considering the binary digits that has 1 on it.
Example: Binary to Octal
1101.012 = ?8
= 001 101 . 010
= 001 101 . 010
= 1 5 . 28
= 15.28
Number SystemsNumber Systems 19
1st group2nd group
4 2 14 2 14 2 1
Add 0 to the right, to complete the grouping for the fractional part of the given binary
Simply add all the number markers considering the binary digits that has 1 on it.
1st group
Binary to Hexadecimal• Since one hexadecimal digit is equivalent to four binary
digits, just group four binary digits, starting from the least significant bit (right side).
• Append 0 to the most significant bit (left side), if the grouping does not have enough to form four binary digits.
• In short, you must complete the grouping of four digits. • If you will be having a fraction (decimal point), append 0
to the least most significant bit (right side) of the given digits to complete the grouping of three bits.
Number SystemsNumber Systems 20
Binary to Hexadecimal (cont.)
• Steps in converting Binary to Hexadecimal:– Group the given digits in four starting from the
right side.– If the grouping is not complete, place 0 to
complete the grouping.– Once you have grouped it into three digits, you
starting converting the binary digits into decimal values following the concepts of binary digits (8, 4, 2, 1) starting from the right.
Number SystemsNumber Systems 21
Example: Binary to Hexadecimal
11010102 = ?16
= 0110 1010
= 0110 1010
= 6 A16
= 6A16
Number SystemsNumber Systems 22
1st group2nd group
8 4 2 1
Add 0 to the left, to complete the grouping
Simply add all the number markers considering the binary digits that has 1 on it.
8 4 2 1
Example: Binary to Hexadecimal
1101.012 = ?16
= 1101 . 0100
= 1101 . 0100
= D . 416
= D.416
Number SystemsNumber Systems 23
1st group
8 4 2 1
Add 0 to the left, to complete the grouping
Simply add all the number markers considering the binary digits that has 1 on it.
8 4 2 1
1st group
Decimal to Binary
• Converting a decimal number to a binary number is done by successively dividing the decimal number by 2 on the left side of the radix.
• If you will have a fractional part of the given decimal, successively multiplying the decimal number by 2 on the right side of the radix.
Number SystemsNumber Systems 24
Decimal to Binary (cont.)
• Steps in converting Decimal to Binary:– Divide the given decimal number with the base
number you are converting it to, which is 2.– Whatever the answer you will get in the division
will be divided again with the base (2) until you cannot divide the answer anymore with 2.
– The remainder that you will get will be the one you consider as your converted answer.
Number SystemsNumber Systems 25
Example: Decimal to Binary
610 = ?2
= 1102
= 6/2 0= 3/2 1= 1/2 1= 0/2
Number SystemsNumber Systems 26
Remainder of the division, will only have two values since it is in base 2, meaning you can only have 1 or 0 as a remainder.
In reading the answer, you should read it upward.
remainder
Example: Decimal to Binary
6.62510 = ?2
= 110.1012
= .625*2= 1.25*2 1= 0.5*2 0= 1.0 1
Number SystemsNumber Systems 27
You will be multiplying only the decimal numbers with base 2 until you reach 0 in the decimal place.
In reading the answer, you should read it downward.
Stop here, because it is already 0
Decimal to Octal
• Converting a decimal number to an octal number is done by successively dividing the decimal number by 8 on the left side of the radix.
• If you will have a fractional part of the given decimal, successively multiplying the decimal number by 8 on the right side of the radix.
Number SystemsNumber Systems 28
Decimal to Octal (cont.)
• Steps in converting Decimal to Octal:– Divide the given decimal number with the base
number you are converting it to, which is 8.– Whatever the answer you will get in the division
will be divided again with the base (8) until you cannot divide the answer anymore with 8.
– The remainder that you will get will be the one you consider as your converted answer.
Number SystemsNumber Systems 29
Example: Decimal to Octal
6610 = ?8
= 1028
= 66/8 2= 8/8 0= 1/8 1= 0/8
Number SystemsNumber Systems 30
In reading the answer, you should read it upward.
Remainder of the division, will only have 0-7 values since it is in base 8
remainder
Example: Decimal to Octal
66.62510 = ?8
= 102.58
= .625*8= 5. 0 5
Number SystemsNumber Systems 31
You will be multiplying only the decimal numbers with base 8 until you reach 0 in the decimal place.
In reading the answer, you should read it downward.
Stop here, because it is already 0
Decimal to Hexadecimal
• Converting a decimal number to a hexadecimal number is done by successively dividing the decimal number by 16 on the left side of the radix
• If you will have a fractional part of the given decimal, successively multiplying the decimal number by 16 on the right side of the radix.
Number SystemsNumber Systems 32
Decimal to Hexadecimal (cont.)
• Steps in converting Decimal to Hexadecimal:– Divide the given decimal number with the base number
you are converting it to, which is 16.– Whatever the answer you will get in the division will be
divided again with the base (16) until you cannot divide the answer anymore with 16.
– The remainder that you will get will be the one you consider as your converted answer.
Number SystemsNumber Systems 33
Example: Decimal to Hexadecimal
28610 = ?16
= 11E16
= 286/16 14= 17/16 1= 1/16 1= 0/16
Number SystemsNumber Systems 34
In reading the answer, you should read it upward.
The value 14 should be converted to hexadecimal format
Remainder of the division, will only have 0-9, A-F values since it is in base 16
remainder
Example: Decimal to Hexadecimal
286.62510 = ?16
= 11E.A16
= .625*16= 10.0 10
Number SystemsNumber Systems 35
You will be multiplying only the decimal numbers with base 8 until you reach 0 in the decimal place.
In reading the answer, you should read it downward.
Stop here, because it is already 0
Octal to Decimal• Remember that Octal numbers are based on the radix of 8 while
Decimal numbers are based on the radix of 10.• Remember also that Octal will only be represented with value 0-7.• Steps in converting Octal to Decimal:
– Place a number marker on the top of the given digits, starting from 0 up the last given digits—starting from the right to determine the exponent to use.
– Considering all the given digits, multiply it with the base number of the given digits (which is base 8) and raised it with power of the number corresponded in the number marker you placed on the top of the given digits.
Number SystemsNumber Systems 36
Example: Octal to Decimal
7618 = ?10
= 761
= 7*82 + 6*81 + 1*80
= 56 + 48 + 1
= 10510
Number SystemsNumber Systems 37
2 1 0
Place the number marker on the top of the given digits, starting from the right, starting from 0 up to the last given digit on the left.
Example: Octal to Decimal
761.188 = ?10
= 761.15
= 7*82 + 6*81 + 1*80 + 1*8-1 + 8*8-
2
= 448 + 48 + 1 +0.125+0.125
= 497.2510
Number SystemsNumber Systems 38
2 1 0 -1 -2
If dealing with fraction in octal the marker will start at the right side of the decimal point and starting with the -1 up to the last given digit.
1*2-2 will be converted into 1*2½ which results into 0.25 because you will be dividing
1 / 4 which comes from 1*2½
Octal to Binary
• Since one octal digit is equivalent to three binary digits, just convert the individual octal digit into three binary digits.
• Steps in converting Octal to Binary:– Convert each of the given octal number by simply
using the concept of (4, 2, 1).– Place a binary 1 to correspond the given octal
number.
Number SystemsNumber Systems 39
Example of Octal to Binary
7618 = ?2
= 7 111
= 6 110
= 1 001
= 111 110 0012
Number SystemsNumber Systems 40
4 2 1
4 2 1
4 2 1
Simply add all the number markers considering the binary digits that has 1 on it, to get the octal number given.
Example of Octal to Binary
761.258= ?2
= 111 110 001 . 010 101
= 111 110 001.0101012
Number SystemsNumber Systems 41
2 57 6 1
4 2 1 4 2 1 4 2 1 4 2 1 4 2 1
Octal to Hexadecimal
• When converting an octal digit to a hexadecimal digit, you must first convert the octal number to binary number and group it by four and convert the grouped digits to hexadecimal by using the concept of (8, 4, 2, 1).
• If the digits is not enough to form a grouping of four then append 0 on the left side of the digits.
• If the given octal have fraction, then append 0 on the right side of the given digits.
Number SystemsNumber Systems 42
Octal to Hexadecimal (cont.)
• Steps in converting Octal to Hexadecimal:– Convert the octal digits in binary by considering
each given digits and represent it in binary using the concept (4, 2, 1).
– Once it is in binary, that’s the time you convert the binary into hexadecimal, by grouping it into four.
Number SystemsNumber Systems 43
Example: Octal to Hexadecimal
7618 = ?16
= 111 110 001
= 0001 1111 0001
= 1F116
Number SystemsNumber Systems 44
7 6 1
1 F 1
Example: Octal to Hexadecimal
761.758= ?16
= 111 110 001 . 111 101
= 0001 1111 0001 . 1111 0100
= 1F1.F416
Number SystemsNumber Systems 45
7 6 1
1 F 1
7 5
F 4
Hexadecimal to Binary
• Since one hexadecimal digit is equivalent to four binary digits, just convert the individual hexadecimal digit into four binary digit
Number SystemsNumber Systems 46
Example: Hexadecimal to Binary
7AE316 = ?2
= 7 0111 A 1010E 1110 3 0011
= 0111 1010 1110 00112
Number SystemsNumber Systems 47
Example: Hexadecimal to Binary
7AE.316 = ?2
= 7 0111 A 1010E 1110 3 0011
= 0111 1010 1110 . 00112
Number SystemsNumber Systems 48
Hexadecimal to Octal
• When converting an hexadecimal digit to an octal digit, you must first convert the hexadecimal number to binary number and group it by three and convert the grouped digits to octal by using the concept of (4, 2, 1).
• If the digits is not enough to form a grouping of three then append 0 on the left side of the digits.
• If the given hexadecimal have fraction, then append 0 on the right side of the given digits.
Number SystemsNumber Systems 49
Hexadecimal to Octal (cont.)
• Steps in converting Hexadecimal to Octal:– Convert the hexadecimal digits in binary by
considering each given digits– Once converted to binary group the binary into
three and using the concept (4, 2, 1).
Number SystemsNumber Systems 50
Example: Hexadecimal to Octal
7AE316 = ?8
= 7 0111 A 1010E 1110 3 0011
= 0 111 101 011 100 0112
= 753438
Number SystemsNumber Systems 51
7 5 3 4 3
Example: Hexadecimal to Octal
7AE.316 = ?8
= 7 0111 A 1010E 1110 3 0011
= 0111 1010 1110 . 00112
= 011 110 101 110 . 001 1002
= 3656.148
Number SystemsNumber Systems 52
3 6 5 6 1 4
Hexadecimal to Decimal• Each hexadecimal position is weighted with a power of
16. • Digits on the left side of the radix point has a positive
exponent while on the right side of the radix point has a negative exponent.
• Converting a hexadecimal number to a decimal number is done by successively multiplying the decimal number by 16 on the left side of the radix
• If you will have a fractional part of the given decimal, successively multiplying the decimal number by 16 on the right side of the radix.
Number SystemsNumber Systems 53
Hexadecimal to Decimal (cont.)
• Steps in converting Hexadecimal to Decimal:– Place a number marker on the top of the given
number for determining the exponent to be used.– Get the individual digit and multiply it by the base
number (16) and raised it with the exponent corresponds to the number marker you place on each digit, then to the addition operation.
Number SystemsNumber Systems 54
Introduction to Computer Introduction to Computer ProgrammingProgramming
5555
Example: Hexadecimal to Decimal
286.A16 = ?10
= 286.A
= 2*162 + 8*161 + 6*160 + A*16-1
= 646. 62510
Number SystemsNumber Systems 56
2 1 0 -1
Example: Hexadecimal to Decimal
286A16 = ?10
= 286A
= 2*163 + 8*162 + 6*161 + A*160
= 1034610
Number SystemsNumber Systems 57
3 2 1 0
Review of Number Systems
Common Number Systems
System Base Symbols
Used by humans?
Used in computers?
Decimal 10 0, 1, … 9 Yes No
Binary 2 0, 1 No Yes
Octal 8 0, 1, … 7 No No
Hexa-decimal
16 0, 1, … 9,
A, B, … F
No No
Quantities/Counting (1 of 3)
Decimal Binary Octal
Hexa-decimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7p. 33
Quantities/Counting (2 of 3)
Decimal Binary Octal
Hexa-decimal
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
Quantities/Counting (3 of 3)
Decimal Binary Octal
Hexa-decimal
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17 Etc.
Conversion Among Bases
• The possibilities:
Hexadecimal
Decimal Octal
Binary
Quick Example
2510 = 110012 = 318 = 1916
Base
Decimal to Decimal
Hexadecimal
Decimal Octal
Binary
Next slide…
12510 => 5 x 100 = 52 x 101 = 201 x 102 = 100
125
Base
Weight
Binary to Decimal
Hexadecimal
Decimal Octal
Binary
Binary to Decimal
• Technique– Multiply each bit by 2n, where n is the “weight” of
the bit– The weight is the position of the bit, starting from
0 on the right– Add the results
Example
1010112 => 1 x 20 = 11 x 21 = 20 x 22 = 01 x 23 = 80 x 24 = 01 x 25 = 32
4310
Bit “0”
Octal to Decimal
Hexadecimal
Decimal Octal
Binary
Octal to Decimal
• Technique– Multiply each bit by 8n, where n is the “weight” of
the bit– The weight is the position of the bit, starting from
0 on the right– Add the results
Example
7248 => 4 x 80 = 42 x 81 = 167 x 82 = 448
46810
Hexadecimal to Decimal
Hexadecimal
Decimal Octal
Binary
Hexadecimal to Decimal
• Technique– Multiply each bit by 16n, where n is the “weight”
of the bit– The weight is the position of the bit, starting from
0 on the right– Add the results
Example
ABC16 => C x 160 = 12 x 1 = 12 B x 161 = 11 x 16 = 176 A x 162 = 10 x 256 = 2560
274810
Decimal to Binary
Hexadecimal
Decimal Octal
Binary
Decimal to Binary
• Technique– Divide by two, keep track of the remainder– First remainder is bit 0 (LSB, least-significant bit)– Second remainder is bit 1– Etc.
Example12510 = ?2
2 125 62 12 31 02 15 12 7 12 3 12 1 12 0 1
12510 = 11111012
Octal to Binary
Hexadecimal
Decimal Octal
Binary
Octal to Binary
• Technique– Convert each octal digit to a 3-bit equivalent
binary representation
Example7058 = ?2
7 0 5
111 000 101
7058 = 1110001012
Hexadecimal to Binary
Hexadecimal
Decimal Octal
Binary
Hexadecimal to Binary
• Technique– Convert each hexadecimal digit to a 4-bit
equivalent binary representation
Example10AF16 = ?2
1 0 A F
0001 0000 1010 1111
10AF16 = 00010000101011112
Decimal to Octal
Hexadecimal
Decimal Octal
Binary
Decimal to Octal
• Technique– Divide by 8– Keep track of the remainder
Example123410 = ?8
8 1234 154 28 19 28 2 38 0 2
123410 = 23228
Decimal to Hexadecimal
Hexadecimal
Decimal Octal
Binary
Decimal to Hexadecimal
• Technique– Divide by 16– Keep track of the remainder
Example123410 = ?16
123410 = 4D216
16 1234 77 216 4 13 = D16 0 4
Binary to Octal
Hexadecimal
Decimal Octal
Binary
Binary to Octal
• Technique– Group bits in threes, starting on right– Convert to octal digits
Example10110101112 = ?8
1 011 010 111
1 3 2 7
10110101112 = 13278
Binary to Hexadecimal
Hexadecimal
Decimal Octal
Binary
Binary to Hexadecimal
• Technique– Group bits in fours, starting on right– Convert to hexadecimal digits
Example10101110112 = ?16
10 1011 1011
2 B B
10101110112 = 2BB16
Octal to Hexadecimal
Hexadecimal
Decimal Octal
Binary
Octal to Hexadecimal
• Technique– Use binary as an intermediary
Example10768 = ?16
1 0 7 6
001 000 111 110
2 3 E
10768 = 23E16
Hexadecimal to Octal
Hexadecimal
Decimal Octal
Binary
Hexadecimal to Octal
• Technique– Use binary as an intermediary
Example1F0C16 = ?8
1 F 0 C
0001 1111 0000 1100
1 7 4 1 4
1F0C16 = 174148
Binary Addition
Introduction to Computer Introduction to Computer ProgrammingProgramming
104104
Binary Addition
Binary Addition
• Two 1-bit values
pp. 36-38
A B A + B
0 0 0
0 1 1
1 0 1
1 1 10“two”
Binary Addition
• Two n-bit values– Add individual bits– Propagate carries– E.g.,
10101 21+ 11001 + 25 101110 46
11
Introduction to Computer Introduction to Computer ProgrammingProgramming
107107
Binary Addition
Introduction to Computer Introduction to Computer ProgrammingProgramming
108108
Binary Subtraction
Introduction to Computer Introduction to Computer ProgrammingProgramming
109109
Binary Subtraction
Fractions
• Decimal to decimal
pp. 46-50
3.14 => 4 x 10-2 = 0.041 x 10-1 = 0.1
3 x 100 = 3 3.14
Fractions
• Binary to decimal
10.1011 => 1 x 2-4 = 0.06251 x 2-3 = 0.1250 x 2-2 = 0.01 x 2-1 = 0.50 x 20 = 0.01 x 21 = 2.0 2.6875
Introduction to Computer Introduction to Computer ProgrammingProgramming
112112
Fractions
Fractions
Introduction to Computer Introduction to Computer ProgrammingProgramming
114114
Fractions
Introduction to Computer Introduction to Computer ProgrammingProgramming
115115
Fractions
Introduction to Computer Introduction to Computer ProgrammingProgramming
116116
Fractions
Fractions
• Decimal to binary
p. 50
3.14579
.14579x 20.29158x 20.58316x 21.16632x 20.33264x 20.66528x 21.33056
etc.11.001001...
Thank you