400 likes | 873 Views
Lecture 5 Number System. CSCS100 - Fall 2007 – Forman Christian College Asher Imtiaz Wajeeha Akram. *Several of these slides have been adapted and modified from LUMS CS101 course (Dr Salim Tariq), VU CS101 slides (Dr. Altaf A. Khan) and Peter Norton’s supplementary material.
E N D
Lecture 5Number System CSCS100 - Fall 2007 – Forman Christian College Asher Imtiaz Wajeeha Akram *Several of these slides have been adapted and modified from LUMS CS101 course (Dr Salim Tariq), VU CS101 slides (Dr. Altaf A. Khan) and Peter Norton’s supplementary material.
“There are 10 kinds of people in the world: those who understand binary and those who don't.” Ben Hammond
Goals • To become familiar with the number system used by the microprocessors • Binary Numbers • Decimal to Binary Conversions
How Computers Represent Data • Number systems • A manner of counting • Several different number systems exist • Decimal number system • Used by humans to count • Contains ten distinct digits • Digits combine to make larger numbers
How Computers Represent Data • Bits and bytes • Binary numbers are made of bits • Bit represents a switch • A byte is 8 bits • Byte represents one character
Number Systems • Decimal System • Base 10 • Binary System • Base 2 • Octal System • Base 8 • Hexadecimal System • Base 16
Decimal Number System • Base 10 system (Ten digits: 0, 1, 2, …, 9) • Counting process • Every digit goes through a cycle 0 9 • After a complete cycle of a lower significant digit (0 through 9) immediately higher digit is incremented by 1, while the lower significant digit is reset to 0. • 012…91011…192021 and so on
Decimal Number System • Expanded form • 5429 = 5,000 + 400 + 20 + 9 OR • 5,429 = 5x103 + 4x102 + 2x101 + 9x100 • Addition • Carry • Subtraction • Borrow • Negative number
Binary Number System • Base 2 system (2 digits; 0, 1) • Counting 0,1,10,11,100,101,110,111,1000,…
Binary Number System Expanded form • (110010)2 = 1x25 + 1x24 + 1x21 = 32 + 16 + 2 = (50)10 • (1110)2 = 8+4+2=(14)10
Binary Number System N zeros
Decimal & Binary conversion • Convert (289)10 into binary • Convert (10111010)2 into decimal
Hexadecimal Number System • Base 16 system (0,1,…,9,A,B,…F digits) • A (10) 10 • F (15)10 • Counting • 0,1,2,…,A,B,…,E,F,10,11,…1E,1F,20,… • Decimal Equivalents • (10)16 = (1 x 161) + (0 x 160) = (16)10 • (F2)16 = (15 x 161) + (2 x 160) = (242)10
Hexadecimal Number System • Hexadecimal & decimal conversions • (462)10 (?)16 • (462)16 (?)10
Hexadecimal Number System • Binary & Hexadecimal Conversions • Combine 4 binary digits into a hexadecimal number • Break each hexadecimal digit into 4 binary digits
Hexadecimal& Binary Conversion 8 4 2 1
Power of 2 • Inventor of chess • All that he asked was to place one grain of rice on the first box and keep on doubling • Money Game • I will give you Rs 100,000 everyday for 30 days. You will give me 1 paisa on the 1st day but will double the amount every day for 30 days. • 230-1 ~ 10.7 x 108
Base 16 (Hexadecimal) • (100)10 = (64)16= 6*16 + 4*1 100 • |6 – 4 Repeatedly divide by 16, until you get a number less than 16. (1000)10 = (3E8)16 = 3*16*16 + 14*16 + 8*1 1000 A-10, B-11, C-12 16 |62 – 8 D-13, E-14, F-15 16 |3 - 14
Maximum Number in n-bits • 2 bits, max number is 11 (3) • 3 bits, max number is 111 (7) • 8 bits, max number is 11111111 (255) • n bits, max number is ???