Internal Information Representation and Processing CSCE 106 - Fundamentals of Computer Science Dr. Awad Khalil Computer Science & Engineering Department The American University in Cairo CSCI 532 - Contemporary Computer Design
Decimal Number System We are used to the decimal number system which is a positional number system The decimal number 4386 represents the value: 41000 + 3 100 + 8 10 + 6 1 In general, the decimal number dn dn-1 . . . d1 d0 represents the value: The digit at the left is called the most significant digit The most significant digit has the largest power of ten The digit at the right is called the least significant digit The concept of zero is a cornerstone in the decimal number system. It enables us to multiply by 10 by simply adding a zero as a least significant digit. Similarly, we can divide by zero by remove the least significant zero or inserting a decimal point. 1234 10 = 12340 1234 / 10 = 123.4 Internal Information Representation - slide 1 Fundamentals of Computer Science – Awad Khalil
Other Radices The positional number system is called also the Arabic number system (the Arabs have discovered the 0) Other bases (called also radices) are possible A digit in base b is between 0 and b-1 Base 10 digits: 0, 1, …, 9 (called also decimal digits) Base 2 digits: 0 and 1 (called also binary digits or bits) Base 3 digits: 0, 1, 2 Base 8 digits: 0, 1, …, 7 (called also octal digits) Base 16 digits: 0, 1, …, 9, A, B, C, D, E, F (called also hexadecimal digits) The number (dn dn-1 . . . d1 d0)b represents the value: Examples: (207)8 = 2 82 + 0 81 + 7 80 = 128 + 0 + 7 = 135 (1011)2 = 1 23 + 0 22 + 1 21 + 1 20 = 8 + 0 + 2 + 1 = 11 Internal Information Representation - slide 2 Fundamentals of Computer Science – Awad Khalil
Binary, Octal, and Hexadecimal Number Systems Computers use the binary number system Two binary digits: 0 and 1 called bits In the hardware circuitry, 0 represents LOW voltage, while 1 represents HIGH voltage Information inside the computer is represented by 0’s and 1’s The integer values 0 to 16, represented in four number systems are shown below: 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 7 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 16 10000 20 10 Decimal Binary Octal Hexadecimal Advantages of the octal and hexadecimal numbers: Reduce the length of numbers Are more readable than binary numbers Can be easily converted to/from binary Internal Information Representation - slide 3 Fundamentals of Computer Science – Awad Khalil
Conversions between Number Systems A number in base b can be easily converted to base 10 using the following equation: Examples: We can also convert a decimal number N to obtain the number (dn dn-1 . . . d1 d0 )b in base b using the following algorithm: (2012)3 = 2 33 + 0 32 + 1 31 + 2 30 = 54 + 0 + 3 + 2 = 59 (A0F)16 = 10 162 + 0 161 + 15 160 = 2560 + 0 + 15 = 2575 i := 0; q := N; repeat di := q mod b; q := q div b; i := i + 1; until q = 0; Question: Convert 50 to base 2 Answer: d0 = 50 mod 2 = 0, q = 50 div 2 = 25 d1 = 25 mod 2 = 1, q = 25 div 2 = 12 d2 = 12 mod 2 = 0, q = 12 div 2 = 6 d3 = 6 mod 2 = 0, q = 6 div 2 = 3 d4 = 3 mod 2 = 1, q = 3 div 2 = 1 d5 = 1 mod 2 = 1, q = 1 div 2 = 0 Thus, 50 = (110010)2 Question: Convert 50 to base 3 Answer: d0 = 50 mod 3 = 2, q = 50 div 3 = 16 d1 = 16 mod 3 = 1, q = 16 div 3 = 5 d2 = 5 mod 3 = 2, q = 5 div 3 = 1 d3 = 1 mod 3 = 1, q = 1 div 3 = 0 Thus, 50 = (1212)3 Internal Information Representation - slide 4 Fundamentals of Computer Science – Awad Khalil
More Conversions Answer: Suppose we want to convert a number from base 3 to base 2, we can convert it first to base 10 and then to base 2 Example: Convert (1012)3 to base 2 Answer: (1012)3 = 1 33 + 0 32 + 1 31 + 2 30 = 27 + 3 + 2 = 32 d0 = 32 mod 2 = 0, q = 32 div 2 = 16 d1 = 16 mod 2 = 0, q = 16 div 2 = 8 d2 = 8 mod 2 = 0, q = 8 div 2 = 4 d3 = 4 mod 2 = 0, q = 4 div 2 = 2 d4 = 2 mod 2 = 0, q = 2 div 2 = 1 d5 = 1 mod 2 = 1, q = 1 div 2 = 0 Thus, (1012)3 = 32 = (100000)2 It is easy to convert numbers between the binary, octal, and hexadecimal systems Every 3 binary digits can be converted into an octal digit starting at the least significant bit Every 4 binary digits can be converted into a hexadecimal digit Example: (10100110)2 = (246)8 = (A6)16 Internal Information Representation - slide 5 Fundamentals of Computer Science – Awad Khalil
Computer Representation of Information Basic unit of information is the Bit or Binary digit. With a single bit, we can represent two distinct values 0 and 1. With two bits, we can represent four distinct values: 00, 01, 10, and 11. In general, with m bits, we can represent 2m distinct values. A byte is a grouping of 8 bits. A word is a grouping of either 16, 32, or 64 bits, depending on the computer system. A word is typically 32 bits on most systems, a half word is 16 bits, and a double word is 64 bits. Bit = 0 or 1 Byte = 8 bits Half Word = 2 bytes = 16 bits Word = 4 bytes = 32 bits Long Word = 8 bytes = 64 bits Internal Information Representation - slide 6 Fundamentals of Computer Science – Awad Khalil
Binary Addition The addition of 3 bits a + b + c produces a sum bit and a carry bit. Signed Integers are represented in 2’s complement notation. Addition of integers in 2’s complement notation results in a signed integer. Although a carry out is produced in the 2nd and 4th computations, it is ignored. Examples: carry 11110 carry 111011000 01001101 +77 11101101 –19 + 00101011 +43 + 10101110 –82 sum 01111000 +120 sum 10011011 –101 11001101 –51 01101101 +109 sum 11111000 –8 sum 00011011 +27 a b c carry sum 0 0 0 0 0 0 0 1 0 1 0 1 0 0 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 0 1 1 0 1 0 1 1 1 1 1 a + b + c Internal Information Representation - slide 7 Fundamentals of Computer Science – Awad Khalil
The Discipline of Computing Computing is a relatively young academic discipline. We distinguish between applications of the computer within other disciplines such as business, engineering, and sciences, and the nature of computing itself. Peter Denning gave the following broad definition of the field of Computer Science: Computer Science is the body of knowledge dealing with the design, analysis, implementation, efficiency, and application of processes that transform information. The fundamental question underlying all of computer science is "what can be automated?" Nine general subject areas combine to make up the discipline of Computing. These are shown below: Internal Information Representation - slide 8 Fundamentals of Computer Science – Awad Khalil
The Discipline of Computing Internal Information Representation - slide 9 Fundamentals of Computer Science – Awad Khalil