Computer Fundamentals and Programming: Number System and Data Representation PDF
Document Details
Uploaded by Deleted User
Tags
Summary
This document provides an overview of number systems and data representation in computers. It explains the basic concepts of binary, decimal, octal, and hexadecimal number systems, and how they are used in computers. It also contains examples of converting between these systems.
Full Transcript
# Number System and Data Representation Modern computers are remarkably homogeneous in their approach to arithmetic and logical data processing: most utilize the same number format, and can be classified as 8, 16, 32, or 64-bit architectures (known as their data width), which means the number of bi...
# Number System and Data Representation Modern computers are remarkably homogeneous in their approach to arithmetic and logical data processing: most utilize the same number format, and can be classified as 8, 16, 32, or 64-bit architectures (known as their data width), which means the number of bits of binary data that are operated on by typical instructions, or held in typical data registers. There are also a relatively small number of techniques for number handling. This was not the case in early computers where a profusion of nonstandard data widths and formats abounded, most of which are purely of historical significance today. The basic unit used in computer data storage is called a bit (binary digit). Computers use these little bits, which are composed of ones and zeros, to do things and talk to other computers. All your files, for instance, are kept in the computer as binary files and translated into words and pictures by the software (which is also ones and zeros). This two number system, is called a "binary number system” since it has only two numbers in it. The decimal number system in contrast has ten unique digits, zero through nine. ## The Number System ### Basic Terminology | System | Base | Digits | |---|---|---| | Binary | 2 | 0 1 | | Octal | 8 | 0 1 2 3 4 5 6 7 | | Decimal | 10 | 0 1 2 3 4 5 6 7 8 9 | | Hexadecimal | 16 | 0 1 2 3 4 5 6 7 8 9 A B C D E F | A decimal number system has ten digits range from 0-9. Any decimal number can be represented as a string of these digits since there is ten decimal digits, therefore the base or radix of this system is 10. In binary numbers, we have two digits 0 and 1 and they can also be represented as a string of theses two-digit called bits. The base of binary number system is 2. An octal system has eight-digit ranges from 0-7. Thus the base number is 8. While, the hexadecimal number system has 16 digits range from 0-9 and A-F. Thus 10 is A; 11 is B; 12 is C; 13 is D; 14 is E; 15 is F. There are many methods or techniques which can be used to convert numbers from one base to another. We will demonstrate here the following: ## Decimal to Binary: - Dividing each new quotient by 2 and writing the remainders to the right of each dividend. Stop when the quotient is 1. - Write the answer from the bottom to top. - In case decimal point, the fractional part is multiplied by 2, then you will stop if the multiplicand is less than point one (.1). **Example: 78.25<sub>10</sub>** **Whole number: 78** | Step | Operation | Result | Remainder | Equivalent | |---|---|---|---|---| | 1 | 78/2 | 39.00 | 0.00 x 2 | 0 | | 2 | 39/2 | 19.50 | 0.50 x 2 | 1 | | 3 | 19/2 | 9.50 | 0.50 x 2 | 1 | | 4 | 9/2 | 4.50 | 0.50 x 2 | 1 | | 5 | 4/2 | 2.00 | 0.00 x 2 | 0 | | 6 | 2/2 | 1.00 | 0.00 x 2 | 0 | | 7 | 1/2 | 0.50 | 0.50 x 2 | 1 | **Decimal number: 0.25** | Step | Operation | Result | Remainder | Equivalent | |---|---|---|---|---| | 1 | 0.25 x 2 | 0.50 | 0.50 | 0 | | 2 | 0.50 x 2 | 1.00 | 0.00 | 1 | **Final answer: 1001110.01<sub>2</sub>** ## Binary to Decimal - Multiply the binary numbers by two (2) raise from zero (0) to nth power. - Start to multiply from right to left. - Then get the sum. - For integers with decimal point, start from the left to right. - Multiply by 2 raise from -1 to –n. - Then get the sum. **Example: 1001110.01<sub>2</sub>** **Whole number: 1001110** | Step | Operation | Result | Sum | |---|---|---|---| | 1 | 0 x 2<sup>0</sup> | 0.00 | | | 2 | 1 x 2<sup>1</sup> | 2.00 | | | 3 | 1 x 2<sup>2</sup> | 4.00 | | | 4 | 1 x 2<sup>3</sup> | 8.00 | 78 | | 5 | 0 x 2<sup>4</sup> | 0.00 | | | 6 | 0 x 2<sup>5</sup> | 0.00 | | | 7 | 1 x 2<sup>6</sup> | 64.00 | | **Decimal point: 0.01** | Step | Operation | Result | Remainder | |---|---|---|---| | 1 | 0 x 2<sup>-1</sup> | 0.00 | | | 2 | 1 x 2<sup>-2</sup> | 0.25 | 0.25 | **Final answer: 78.25<sub>10</sub>** ## Decimal to Octal: - Dividing each new quotient by 8 and writing the remainders to the right of each dividend. Stop when the quotient is less than 8. - Write the answer from the bottom to top. - In case decimal point, the fractional part is multiplied by 8, then you will stop if the multiplicand is less than point one (.1). **Example: 145.253<sub>10</sub>** **Whole number: 145** | Step | Operation | Result | Remainder | Equivalent | |---|---|---|---|---| | 1 | 145/8 | 18.125 | 0.125 x 8 | 1 | | 2 | 18/8 | 2.250 | 0.250 x 8 | 2 | | 3 | 2/8 | 0.250 | 0.250 x 8 | 2 | **Decimal point: 0.253** | Step | Operation | Result | Remainder | Equivalent | |---|---|---|---|---| | 1 | 0.253 x 8 | 2.0.24 | 0.024 | 2 | **Final answer: 221.28** ## Octal to Decimal - Multiply the binary numbers by eight (8) raise from zero (0) to nth power. - Start to multiply from right to left. - Then get the sum. - For integers with decimal point, start from the left to right. - Multiply by 8 raise from -1 to –n. - Then get the sum. **Example: 221.28** **Whole number: 221** | Step | Operation | Result | Sum | |---|---|---|---| | 1 | 1 x 8<sup>0</sup> | 1.00 | | | 2 | 2 x 8<sup>1</sup> | 16.00 | | | 3 | 2 x 8<sup>2</sup> | 128.00 | 145 | **Decimal point: 0.2** | Step | Operation | Result | Remainder | |---|---|---|---| | 1 | 2 x 8<sup>-1</sup> | 0.250 | 0.25 | **Final answer: 145.25<sub>10</sub>** ## Decimal to Hexadecimal: - Dividing each new quotient by 16 and writing the remainders to the right of each dividend. Stop when the quotient is less than 16. - Write the answer from the bottom to top. - In case decimal point, the fractional part is multiplied by 16, then you will stop if the multiplicand is less than point one (.1). **Example: 1628.275<sub>10</sub>** **Whole number: 1628** | Step | Operation | Result | Remainder | Equivalent | |---|---|---|---|---| | 1 | 1628/16 | 101.750 | 0.750 x 16 | 12 | | 2 | 101/16 | 6.3125 | 0.3125 x 16 | 5 | | 3 | 6/16 | 0.375 | 0.375 x 16 | 6 | **Decimal number: 0.275** | Step | Operation | Result | Remainder | Equivalent | |---|---|---|---|---| | 1 | 0.275 x 16 | 4.400 | 0.400 | 4 | | 2 | 0.400 x 16 | 6.400 | 0.400 | 6 | | 3 | 0.400 16 | 6.400 | 0.400 | 6 | **Final answer: 65C.466<sub>16</sub>** ## Hexadecimal to Decimal - Multiply the binary numbers by sixteen (16) raise from zero (0) to nth power. - Start to multiply from right to left. - Then get the sum. - For integers with decimal point, start from the left to right. - Multiply by 16 raise from -1 to -n. - Then get the sum. **Example: 65C.466<sub>16</sub>** **Whole number: 65C** | Step | Operation | Result | Sum | |---|---|---|---| | 1 | 12 x 16<sup>0</sup> | 12.00 | | | 2 | 5 x 16<sup>1</sup> | 80.00 | | | 3 | 6 x 16<sup>2</sup> | 1536.00 | 1628 | **Decimal point: 0.2** | Step | Operation | Result | Remainder | |---|---|---|---| | 1 | 4 x 16<sup>-1</sup> | 0.250 | | | 2 | 6 x 16<sup>-2</sup> | 0.0234375 | 0.2749023438 | | 3 | 6 x 16<sup>-3</sup> | 0.0014648438 | | **Final answer: 1628.2749023438<sub>10</sub>** ## Sample Problem: Convert the following: 1. Binary to Decimal: 1011011.011<sub>2</sub> 2. Octal to Decimal: 345.246<sub>8</sub> 3. Hexadecimal to Decimal: 27FA.B21<sub>16</sub> # Characteristics of Computer Speed, accuracy, diligence, storage capability and versatility are some of the key characteristics of a computer. A brief overview of these characteristics is: ## a. Speed The computer can process data very fast, at the rate of millions of instructions per second. Some calculations that would have taken hours and days to complete otherwise, can be completed in a few seconds using the computer. For example, calculation and generation of salary slips of thousands of employees of an organization, weather forecasting that requires analysis of a large amount of data related to temperature, pressure and humidity of various places, etc. ## b. Accuracy Computer provides a high degree of accuracy. For example, the computer can accurately give the result of division of any two numbers up to 10 decimal places. ## c. Diligence When used for a longer period of time, the computer does not get tired or fatigued. It can perform long and complex calculations with the same speed and accuracy from the start till the end. ## d. Storage Capability Large volumes of data and information can be stored in the computer and also retrieved whenever required. A limited amount of data can be stored, temporarily, in the primary memory. Secondary storage devices like floppy disk and compact disk can store a large amount of data permanently. ## e. Versatility Computer is versatile in nature. It can perform different types of tasks with the same ease. At one moment you can use the computer to prepare a letter document and in the next moment you may play music or print a document. Computers have several limitations too. Computer can only perform tasks that it has been programmed to do.