cmp104 lec 2 number system
TRANSCRIPT
![Page 1: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/1.jpg)
Fundamentals of Computer and programming in C
(CMP 104 )
NUMBER SYSTEM
![Page 2: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/2.jpg)
NUMBER SYSTEM
NON-POSITIONAL
SYSTEMNON-POSITIONAL
SYSTEMPOSITIONAL
SYSTEMPOSITIONAL
SYSTEM
New Symbolic representation for every number.Decimal Roman
1,2,3,4,5,6,7,8,9
I, II, III, IV, V, VI, VII, VIII, IX
10 X
11 XI
12 XII
--- ----
New numbers are formed using digits: 0-9 and a decimal point.
10 1 Dec. 1/10 1/100
3 5 . 2 5
3×10 5×1 2×1/10 5×1/100
30 5 .20 .05
35 25
+ +
12/04/23
![Page 3: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/3.jpg)
POSITIONAL NUMBER SYSTEMDecimal (BASE 10) Number System uses 10 symbols 0,1,2,3,4,5,6,7,8,9 called digits.
Integer numbers Integers are whole numbersExamples 1, 2, -3, 50, 675, -560, …..
Decimalnumbers
Real numbersNumbers that has fractions like 687. 345, -49.56, …
12/04/23
![Page 4: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/4.jpg)
NUMBER SYSTEM
• In computer real numbers are referred to as floating point numbers.
• Floating point numbers are represented as<Integer part> <Radix Point> <Fractional part>
34568 . 56735
34568.56735
12/04/23
![Page 5: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/5.jpg)
Decimal Number System
In decimal number system the value of a digit is determined by digit × 10 position . In integer numbers the position is defined as 0,1,2,3,4,5,… starting from the rightmost position and moving one position at a time towards left.
Position 4 3 2 1 010 position 10 4 10 3 10 2 10 1 10 0
Position value 10000 1000 100 10 1Digits 7 2 1 3 4Digit Value 7×10 4 2×10 3 1×10 2 3×10 1 4×10 0
12/04/23
![Page 6: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/6.jpg)
Decimal Number System
Digit Value 7×10 4 2×10 3 1×10 2 3×10 1 4×10 0
Digit Value 70000 2000 100 30 4Integer Number
70000 + 2000 + 100 + 30 + 4
72134
12/04/23
![Page 7: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/7.jpg)
Decimal Number System
In floating point numbers the position is defined as 0,1,2,3,4,5,… starting from the radix point and moving one position at a time towards left, and -1,-2,-3, … starting from the radix point and moving towards right one position at a time.
436.85 = 4 × 100 + 3 × 10 + 6 × 1 . 8 × 0 .1 + 5 × 0.01
Position
Place Value
Digits
12/04/23
![Page 8: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/8.jpg)
Data Representation for Computers
• Computers store numeric (numbers) as well non-numeric (text, images and others) data in binary representation (binary number system).
• Binary number system is a two digits (0 and 1), also referred to as bits, so it is a base 2 system.
• Binary number system is also a positional number system. In this system, the position definition is same as in decimal number system.
• In binary number system the value of a digit is determined by digit × 2 position .
12/04/23
![Page 9: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/9.jpg)
Binary Number System
Position 4 3 2 1 02 position 24 2 3 2 2 2 1 2 0
Position value 16 8 4 2 1Binary Digits 1 1 1 0 1Digit Value 1×2 4 1×2 3 1×2 2 0×2 1 1×2 0
1 × 16 1×8 1×4 0×2 1×116 8 4 0 1
+ = (29)10(11101)2
Value = digit × 2position
12/04/23
![Page 10: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/10.jpg)
Binary Number System
Position
Place Value
Digits
5 75
Floating Point Number (101.11)2= (5.75)10
12/04/23
![Page 11: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/11.jpg)
Can we make new number systems?10 2 3 4 5 6 7 8 …. --- 16
0123456789
101112131415
01
1011
100101110111
10001001101010111100110111101111
012
101112202122
100101102110111112120
0 1 2 3
10 11 12 13 20 21 22 23 30 31 32 33
01234
1011121314202122232430
012345
10111213141520212223
0123456
101112131415162021
01234567
1011121314151617
0123456789ABCDEF
BaseBase
Relationship
Decimal
BinaryBinary
OctalOctal
Hexadecimal
12/04/23
![Page 12: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/12.jpg)
Decimal, Binary, Octal and Hexdecimal
(2057)8 = 2 x 83+0x82+5x81+7x80 = 2 x 512+ 0 x 64 + 5 x 8 + 7 x 1= 1024+0+40+7= (1071)10
(1AF)16 = 1 x 162+Ax161+Fx160
= 1 x 256+ 10 x 16 + 15 x 1= 256+160+15= (431)10
(1101)2 = 1 x 23+1x22+0x21+1x20 = 1 x 8+ 1 x 4 + 0 x 2 + 1 x 1= 8+4+0+1= (13)10
Binary to decimal
Octal to decimal
Hexadecimal to decimal
12/04/23
![Page 13: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/13.jpg)
More examples
Ternary (base-3) numbersQuaternary (base-4) numbersQuinary (base-5) numbers
Mayan number (base-20) system
(211)3 = 2 x 32 + 1 x 31 + 1 x 30 =18 + 3+1 = (22)10
(211)4 = 2 x 42 + 1 x 41 + 1 x 40 =32 + 4+1 = (37)10
(211)5 = 2 x 52 + 1 x 51 + 1 x 50 =50 + 5+1 = (56)10
Senary (base-6 ) numbers?? (base-7) numbersTridecimal or Tredecimal (base-13) numbers
Ex. (211)6 = (?)10 (211)7 = (?)10
(211)13 = (?)10
(211)20= (?)1012/04/23
![Page 14: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/14.jpg)
From Decimal to Another Base1. Divide the decimal
number by the new base.2. Record the remainder as
the right most digit.3. Divide the quotient of the
previous divide by the new base.
4. Record the remainder as the next digit.
5. Repeat step 3& 4 until the quotient becomes 0 in step 3.
ExampleConvert (25)10=()2
(25)10=(11001)2
Number/Base
Quotient Reminder
25/2 12 1
12/2 6 0
6/2 3 0
3/2 1 1
1/2 0 1
12/04/23
![Page 15: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/15.jpg)
From Decimal to Another BaseConvert (42)10=()22 42 Remainder
21 0
10 1
5 0
2 1
1 0
0 1
Convert (952)10=()8
Convert (42)10=(101010)2
8 952 Remainder
119 0
14 7
1 6
0 1
Convert (952)10=(1670)8
12/04/23
![Page 16: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/16.jpg)
From Decimal to Another BaseConvert (428)10=()1616 428 Remainder
26 12 C
1 10 A
0 1
Convert (100)10=()5
Convert (428)10=(1AC)16
5 100 Remainder
20 0
4 0
0 4
Convert (100)10=(400)5
12/04/23
![Page 17: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/17.jpg)
From Decimal to Another BaseConvert (100)10=()44 100 Remainder
25 0
6 1
1 2
0 1
Convert (1715)10=()12
Convert (100)10=(1210)4
12
1715 Remainder
142 11 B
11 10 A
0 11 B
Convert (1715)10=(BAB)12
12/04/23
![Page 18: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/18.jpg)
Converting from a base other than to a base other than 10
1. Convert the original number to a decimal number.2. Convert that decimal number to the new base.
Convert (545)6 to () 4
(545)6 = 5 x 62+4 x 61+ 5 x 60 = 5 x 36 + 4 x 6 + 5 x 1 = 180+24+5= (209)10
4 209 Remainder
52 1
13 0
3 1
0 3
545)6 = (209)10=(3101) 4
12/04/23
![Page 19: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/19.jpg)
Converting form a base other than to a base other than 10
Convert (101110)2 to () 8
(101110)2 = 1 x 25+0 x 24+1 x 23 +1 x 22+1 x 21+0 x 20 = (46)10
8 46 Remainder
5 6
0 5(101110)2 = (46)10=(56)8
(11010011)2 = 1 x 27+1 x 26+0 x 25 +1 x 24+0 x 23 +0 x 22+1 x 21+1 x 20 = (211)10
Convert (11010011)2 to () 16
16
211 Remainder
13 3 3
0 13 D
(11010011)2 = (211)10=D3) 16
12/04/23
![Page 20: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/20.jpg)
Shortcut methods
Binary to Octal1.Start from the rightmost position, make groups of three binary digits.2.Convert each group into octal digit
Convert (101110)2 to () 8 101 110
(5 6)8Octal to Binary1.Convert each octal to three digit binary.2.Combine them in a single binary number (5 6)8
(101 110)212/04/23
![Page 21: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/21.jpg)
Shortcut methods
Convert (562) 8 to ()2
5 6 2
010110101
Convert (6751) 8 to ()2
6
101111110
7 5 1
00112/04/23
![Page 22: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/22.jpg)
Shortcut methods Binary to Hexadecimal conversion1.Starting from the right most position make groups of 4 binary digits2.Convert each group its hexadecimal equivalent digits (0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
Convert (10 1110 0000 1000)2 to () 16
(0)
1110 10 0000 1000
(2) (8)(14)
(2E08) 16
12/04/23
![Page 23: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/23.jpg)
Shortcut methods
Convert (1EBA2F ) 16
(B)
00100001 1110 1011
(1) (2)(E)
Hexadecimal to Binary conversion1.Convert each hexadecimal digit 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F into 4 binary digit.
1111
(F)
12/04/23
![Page 24: Cmp104 lec 2 number system](https://reader035.vdocuments.us/reader035/viewer/2022081505/555e336cd8b42aad058b45c5/html5/thumbnails/24.jpg)
Floating Point
368.65
368.65 x 10-1 = 36.865
368.65 x 10-2 = 3.6865368.65 x 10-3 = .36865
368.65 x 101 = 3686.5
368.65 x 102 = 36865.
.36865 x 103 36865. x 10-2
Mantissa Exponent12/04/23