Iteral Iformatio Represetatio ad Processig CSCE 16 - Fudametals of Computer Sciece Dr. Awad Khalil Computer Sciece & Egieerig Departmet The America Uiversity i Cairo
Decimal Number System We are used to the decimal umber system which is a positioal umber system The decimal umber 4386 represets the value: 4 1 + 3 1 + 8 1 + 6 1 I geeral, the decimal umber d d -1... d 1 d represets the value: d 1 + d 1 1 1 +... + d1 1 + d 1 = di i= 1 1 The digit at the left is called the most sigificat digit The most sigificat digit has the largest power of te The digit at the right is called the least sigificat digit The cocept of zero is a corerstoe i the decimal umber system. It eables us to multiply by 1 by simply addig a zero as a least sigificat digit. Similarly, we ca divide by zero by remove the least sigificat zero or isertig a decimal poit. i 1234 1 = 1234 1234 / 1 = 123.4 Iteral Iformatio Represetatio - slide 1
Other Radices The positioal umber system is called also the Arabic umber system (the Arabs have discovered the ) Other bases (called also radices) are possible A digit i base b is betwee ad b-1 Base 1 digits:, 1,, 9 (called also decimal digits) Base 2 digits: ad 1 (called also biary digits or bits) Base 3 digits:, 1, 2 Base 8 digits:, 1,, 7 (called also octal digits) Base 16 digits:, 1,, 9, A, B, C, D, E, F (called also hexadecimal digits) The umber (d d -1... d 1 d ) b represets the value: Examples: d b + d 1 1 1 b +... + d1 b + d b = di i= (27) 8 = 2 8 2 + 8 1 + 7 8 = 128 + + 7 = 135 (111) 2 = 1 2 3 + 2 2 + 1 2 1 + 1 2 = 8 + + 2 + 1 = 11 b i Iteral Iformatio Represetatio - slide 2
Biary, Octal, ad Hexadecimal Number Systems Computers use the biary umber system Two biary digits: ad 1 called bits I the hardware circuitry, represets LOW voltage, while 1 represets HIGH voltage Iformatio iside the computer is represeted by s ad 1 s The iteger values to 16, represeted i four umber systems are show below: Decimal Biary Octal Hexadecimal 1 1 1 1 2 1 2 2 3 11 3 3 4 1 4 4 5 11 5 5 6 11 6 6 7 111 7 7 8 1 1 8 9 11 11 9 1 11 12 A 11 111 13 B 12 11 14 C 13 111 15 D 14 111 16 E 15 1111 17 F 16 1 2 1 Advatages of the octal ad hexadecimal umbers: Reduce the legth of umbers Are more readable tha biary umbers Ca be easily coverted to/from biary Iteral Iformatio Represetatio - slide 3
Coversios betwee Number Systems A umber i base b ca be easily coverted to base 1 usig the followig equatio: d b + d 1 1 1 b +... + d1 b + d b = di i= b i Examples: (212) 3 = 2 3 3 + 3 2 + 1 3 1 + 2 3 = 54 + + 3 + 2 = 59 (AF) 16 = 1 16 2 + 16 1 + 15 16 = 256 + + 15 = 2575 We ca also covert a decimal umber N to obtai the umber (d d -1... d 1 d ) b i base b usig the followig algorithm: i := ; Questio: Covert 5 to base 2 Questio: Covert 5 to base 3 q := N; Aswer: Aswer: repeat d = 5 mod 2 =, q = 5 div 2 = 25 d = 5 mod 3 = 2, q = 5 div 3 = 16 d d i := q mod b; 1 = 25 mod 2 = 1, q = 25 div 2 = 12 d 1 = 16 mod 3 = 1, q = 16 div 3 = 5 d 2 = 12 mod 2 =, q = 12 div 2 = 6 d 2 = 5 mod 3 = 2, q = 5 div 3 = 1 q := q div b; d 3 = 6 mod 2 =, q = 6 div 2 = 3 d 3 = 1 mod 3 = 1, q = 1 div 3 = i := i + 1; d 4 = 3 mod 2 = 1, q = 3 div 2 = 1 util q = ; d 5 = 1 mod 2 = 1, q = 1 div 2 = Thus, 5 = (1212) 3 Thus, 5 = (111) 2 Iteral Iformatio Represetatio - slide 4
More Coversios Suppose we wat to covert a umber from base 3 to base 2, we ca covert it first to base 1 ad the to base 2 Example: Covert (112) 3 to base 2 Aswer: (112) 3 = 1 3 3 + 3 2 + 1 3 1 + 2 3 = 27 + 3 + 2 = 32 d = 32 mod 2 =, q = 32 div 2 = 16 d 1 = 16 mod 2 =, q = 16 div 2 = 8 d 2 = 8 mod 2 =, q = 8 div 2 = 4 d 3 = 4 mod 2 =, q = 4 div 2 = 2 d 4 = 2 mod 2 =, q = 2 div 2 = 1 d 5 = 1 mod 2 = 1, q = 1 div 2 = Thus, (112) 3 = 32 = (1) 2 It is easy to covert umbers betwee the biary, octal, ad hexadecimal systems Every 3 biary digits ca be coverted ito a octal digit startig at the least sigificat bit Every 4 biary digits ca be coverted ito a hexadecimal digit Example: (1111) 2 = (246) 8 = (A6) 16 Iteral Iformatio Represetatio - slide 5
Computer Represetatio of Iformatio Basic uit of iformatio is the Bit or Biary digit. With a sigle bit, we ca represet two distict values ad 1. With two bits, we ca represet four distict values:, 1, 1, ad 11. I geeral, with m bits, we ca represet 2 m distict values. A byte is a groupig of 8 bits. A word is a groupig of either 16, 32, or 64 bits, depedig o the computer system. A word is typically 32 bits o most systems, a half word is 16 bits, ad a double word is 64 bits. Bit = or 1 Byte = 8 bits Half Word = 2 bytes = 16 bits Word = 4 bytes = 32 bits Log Word = 8 bytes = 64 bits Iteral Iformatio Represetatio - slide 6
Biary Additio The additio of 3 bits a + b + c produces a sum bit ad a carry bit. Siged Itegers are represeted i 2 s complemet otatio. Additio of itegers i 2 s complemet otatio results i a siged iteger. Although a carry out is produced i the 2 d ad 4 th computatios, it is igored. a + b + c a b c carry sum 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Examples: carry 1111 carry 11111 1111 +77 111111 19 + 1111 +43 + 11111 82 sum 1111 +12 sum 11111 11 carry 1111 carry 11111 11111 51 11111 +19 + 1111 +43 + 11111 82 sum 11111 8 sum 1111 +27 Iteral Iformatio Represetatio - slide 7
The Disciplie of Computig Computig is a relatively youg academic disciplie. We distiguish betwee applicatios of the computer withi other disciplies such as busiess, egieerig, ad scieces, ad the ature of computig itself. Peter Deig gave the followig broad defiitio of the field of Computer Sciece: Computer Sciece is the body of kowledge dealig with the desig, aalysis, implemetatio, efficiecy, ad applicatio of processes that trasform iformatio. The fudametal questio uderlyig all of computer sciece is "what ca be automated?" Nie geeral subject areas combie to make up the disciplie of Computig. These are show below: Iteral Iformatio Represetatio - slide 8
The Disciplie of Computig Artificial Itelligece Numeric ad Symbolic Computatio Database Systems Programmig Laguages Algorithms ad Data Structures Computer Architecture Huma-Computer Commuicatio Software Egieerig Operatig Systems Iteral Iformatio Represetatio - slide 9