Numbering Systems (Part 1) PDF
Document Details
Uploaded by Deleted User
Ahram Canadian University
Dr. Dalia Rizk
Tags
Summary
This document provides an introduction to numbering systems, including decimal, binary, octal, and hexadecimal. It explains the concepts of bits and bytes, and how these systems are used in computer science. Conversions between these systems are detailed.
Full Transcript
NUMERIC REPRESENTATION Decimal Binary Hex Two-state binary system consists 00 00000000 00 of only two digits called bits. 01 00000001 01 ▪ On = 1; negat...
NUMERIC REPRESENTATION Decimal Binary Hex Two-state binary system consists 00 00000000 00 of only two digits called bits. 01 00000001 01 ▪ On = 1; negative charge. 02 00000010 02 ▪ Off = 0; no charge. 03 00000011 03 04 00000100 04 Byte = 8 bits grouped together. 05 00000101 05 Hexadecimal system. 06 00000110 06 ▪ Uses 16 digits to represent 07 00000111 07 08 00001000 08 binary numbers. 09 00001001 09 ▪ (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, 10 00001010 0A C, D, E, F) 11 00001011 0B 12 00001100 0C 13 00001101 0D 14 00001110 0E 15 00001111 0F INTRO. TO CS, DR. DALIA RIZK 2 CHARACTER ENCODING ASCII. ▪ American Standard Code for Information Interchange. ▪ Used by personal computers. EBCDIC. ▪ Extended Binary coded Decimal Interchange Code. ▪ Used by mainframe computers. Unicode. ▪ New encoding due to explosion of the Internet. ▪ Can be written in U T F-16 or U T F-8. ▪ Recognized by virtually all computer systems. INTRO. TO CS, DR. DALIA RIZK 3 ASCII CODES ▪ Computers only understand numbers. ▪ ASCII code is the numerical representation of a character such as ‘b' or '@‘ ▪ The ASCII code takes each character on the keyboard and convert it to a binary number Example: ▪ The letter ‘a’ has the binary number 0110 0001 (this is the decimal number 97) ▪ The letter ‘A’ has the binary number 0100 0001 (this is the decimal number 65) INTRO. TO CS, DR. DALIA RIZK 4 ASCII CODES INTRO. TO CS, DR. DALIA RIZK 5 UNICODE ▪ It is an international coding system designed to be used with different language scripts. ▪ Each character or symbol is assigned a unique numeric value, largely within the framework of ASCII. ▪ Unicode provides a unique number for every character, no matter what the platform, no matter what the program, no matter what the language. INTRO. TO CS, DR. DALIA RIZK 6 NUMBERING SYSTEMS IN COMPUTER There are different types of number systems, in which the four main types are: ▪ Binary number system(Base -2) ▪ Octal number system(Base -8) ▪ Decimal number system(Base -10) ▪ Hexadecimal number system(Base -16) INTRO. TO CS, DR. DALIA RIZK 7 NUMBERING SYSTEMS IN COMPUTER Uses of Binary number system: ▪ To represent pixels of an image. ▪ To represent On and OFF in a circuit. ▪ To represent True and False statements. ▪ To represent ASCII codes Uses of Octal Numbers: ▪ In UNIX operating system ▪ In Computing Graphics ▪ In File Protection INTRO. TO CS, DR. DALIA RIZK 8 NUMBERING SYSTEMS IN COMPUTER Uses of the Decimal system: ▪ Financial calculations ▪ Calendar numbers ▪ Counting numbers Uses of Hexadecimal: ▪ Memory locations ▪ De-bugging ▪ To define colors on web pages (red color is represented as ff0000) INTRO. TO CS, DR. DALIA RIZK 9 BINARY NUMBERS SYSTEMS Binary consists of two units 0 and 1, known as bit. ▪ 0 bit means NO (False) while 1 bit means YES (True). ▪ These bits are combined in a group of 8 to form 1 byte, to represent multiple characters and values. ▪ One byte can represent 256 values depending on its arrangement of bit units. ▪ There is no representation for negative integers because we only have 0 and 1. INTRO. TO CS, DR. DALIA RIZK 10 DECIMAL TO BINARY CONVERSION Convert the following number 59 into its equivalent binary form: Step 1:Repeat a division of 59 by 2 and get remainders 59/2 = 29 r 1 29/2 = 14 r 1 Step 2: Arrange from top into right moving to 14/2 = 7 r 0 left, then complete the (8 bit) byte 7/2 = 3 r 1 with zeros 3/2 = 1 r 1 1/2 = 0 r 1 Result = 00111011 INTRO. TO CS, DR. DALIA RIZK 11 BINARY TO DECIMAL CONVERSION Convert the following binary number 10010101 into its equivalent decimal form: Step 1:Multiply each digit from right to left by powers of 2 Step 2: Add results together 128+0+0+16+0+4+0+1 Result = 149 INTRO. TO CS, DR. DALIA RIZK 12 DECIMAL TO OCTAL CONVERSION ▪ Octal Number System has a base of eight and uses the set of values = {0,1,2,3,4,5,6,7} Convert the decimal number (560)10 to its equivalent octal form: Step 1: Repeat a division of decimal 560 by 8 and get remainder (remainder should be between 0 and 7) 560/8 = 70 r 0 70/8 = 8 r 6 Step 2: Arrange digits from top into right 8/8 = 1 r 0 moving to left 1/8 = 0 r 1 Result = (1060)8 INTRO. TO CS, DR. DALIA RIZK 13 OCTAL TO DECIMAL CONVERSION Convert the octal number (215)8 to its equivalent decimal form: Step 1:Multiply each digit from right to left by powers of 8 Step 2: Add results together Result = 128 + 8 +5 = (141)10 INTRO. TO CS, DR. DALIA RIZK 14 OCTAL TO BINARY CONVERSION Convert the octal number (540)8 to its equivalent binary form: Step 1: Put each digit in its equivalent three binary bits from right to left Step 2: Arrange binary numbers from right to left Result = (101100000)2 INTRO. TO CS, DR. DALIA RIZK 15 BINARY TO OCTAL CONVERSION Example: Convert the following binary number (0100010)2 to its equivalent octal form: Step 1: Divide the binary bits into groups of three starting from right to left (complete with zeros for most significant bits) Step 2: Get the octal number of each three bits Step 3: Arrange digits in their octal form from right to left Result = (42)8 INTRO. TO CS, DR. DALIA RIZK 16 HEXADECIMAL NUMBER SYSTEM ▪ Hexadecimal number system has the base of sixteen and has a set of values = {0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F} ▪ Equivalent hexadecimal and binary numbers for decimal numbers are shown in table below: INTRO. TO CS, DR. DALIA RIZK 17 DECIMAL TO HEXADECIMAL CONVERSION Convert the decimal number (960)10 to its equivalent hexadecimal form: Step 1: Repeat a division of 960 by 16 and get remainder 960 / 16 = 60 r 0 60 / 16 = 3 r 12 ------(12 is equivalent to C) 3 / 16 = 0 r 3 Step 2: Arrange remainder digits from top into right moving to left, and substitute the equivalent hexadecimal values Result = (3C0)16 INTRO. TO CS, DR. DALIA RIZK 18 HEXADECIMAL TO DECIMAL CONVERSION Convert the hexadecimal number (7CF)16 to its equivalent decimal form: Step 1: Multiply each digit from right to left (after hexadecimal substitution) by powers of 16 7= 7 , C= 12 , F=15 Step 2: Add results together = (7 * 256) + (12 * 16) + (15 * 1) = 1792 + 192 + 15 = 1999 Result = (1999)10 INTRO. TO CS, DR. DALIA RIZK 19 BINARY TO HEXADECIMAL CONVERSION Convert the binary number (11100011)2 to its equivalent hexadecimal form: Step 1: Divide the binary number into groups of four bits starting from right to left = 1110 0011 Step 2: Get the equivalent hexadecimal for each four bits (convert binary to decimal then get its equivalent hexadecimal) Step 3: Arrange hexadecimal digits from right to left Result = (E3)16 INTRO. TO CS, DR. DALIA RIZK 20 HEXADECIMAL TO BINARY CONVERSION Convert the hexadecimal number (A2B)16 to its equivalent binary form: Step 1: Put each hexadecimal digit in its binary four bits starting from right to left (after substitution: A = 10 , 2 = 2 , B =11) Step 2: Arrange the binary numbers from right to left = (101000101011)2 Result = (101000101011)2 INTRO. TO CS, DR. DALIA RIZK 21 HEXADECIMAL TO OCTAL CONVERSION Convert the hexadecimal number (1BC)16 to its equivalent octal form: Step 1: Put each hexadecimal digit in its binary four bits starting from right to left, and after substitution: 1= 1, B = 11, C = 12 (1 1011 1100)2 Step 2: Divide the resulted binary bits into groups of three bits and get their octal number = 110 111 100 Step 3: Arrange digits in their octal form from right to left Result = (674)8 INTRO. TO CS, DR. DALIA RIZK 22 OCTAL TO HEXADECIMAL CONVERSION Convert the octal number (56)8 to its equivalent hexadecimal form: Step 1: Put each octal digit in its binary three bits form from right to left= 101 110 Step 2: Divide the resulted binary bits into groups of four bits and get its hexadecimal number = 10 1110 Step 3: Arrange digits in their octal form from right to left Result = (2E)16 INTRO. TO CS, DR. DALIA RIZK 23