Units of Data & Fundamental Operations on Bits PDF

Summary

This document provides an introduction to fundamental concepts in data representation and computer operations. It details the use of bits and bytes in computer science, and examples are given. The document also explains different units of information, like kilobits and megabytes. This document is not an exam paper.

Full Transcript

**Units of Data and Fundamental Operations on Bits** **1.0 Introduction** The main use of a computer is to process data into information. Data refers to information in an unorganized and raw form. For the data to be processed, it has to be fed to the computer and then it is processed in batches. I...

**Units of Data and Fundamental Operations on Bits** **1.0 Introduction** The main use of a computer is to process data into information. Data refers to information in an unorganized and raw form. For the data to be processed, it has to be fed to the computer and then it is processed in batches. In this class, we shall be looking at the various units of data, starting from the smallest basic unit to the largest. We shall also introduce the fundamental operations that can be performed on the smallest unit of data. **1.1 Units of Information** Bits are the shortened form of the term binary digit and it represents information in two states only. The two states are zeros and ones (0 and 1). The 0 represents OFF or LOW states while the 1 represents ON or HIGH states. The two states can be likened to light in a room with two options only, the lights can be ON or OFF with no state in between. Two important factors of a bit are its duration and the difference in voltage levels between the 0 and the 1. Example 1: Figure showing a string of bits 10110 In example 1 is displayed a string of 5 bits. A +5v was used to represent the ON state (1) and 0v used for the OFF state (0). This is not fixed, and can be +5v for 1 and -5v for 0, +10v for 1 and +5v for 0. The duration of each bit in the example will depend on the duration of the pulse. If the pulse lasted for 10 seconds, the each bit will have a duration of 10/5 = 2 seconds. A group of eight bits put together is referred to as a byte. The amount of information contained increases as the number of bits increases. This is because each of the bits can be either LOW or HIGH and the different sequences of ONs and OFFs can be used to convey information. 8 bits put together can be used to represent the various characters in most languages, and this was then adopted to be 1 byte. Bits is usually represented with a lower case letter 'b', while the upper case later 'B' is used to represent a byte. Example 2: Figure showing one byte: 10110010 A computer has the capability to process large amount of data at a time. Feeding just 8 bits (1 byte) to a computer to process at a time is a waste of processing power. Just like tying a small bucket to a horse to pull. The number of bits a particular computer can process at a particular time is referred to as word. For example in a 32-bit computer, the word length is 32 bits and such a computer can address 32 memory locations for processing at a particular point of time. Other examples of word lengths are 64bits, 16bits etc. **1.2 Measures of Units of Information** Computers can process and store large amount of data and information. As such terms are used to refer to this large aggregate amount of bits or bytes. Table 1.1 shows the various units of information you need to comprehend. **Name** **Representation** **No of bits** **No of Bytes** ----------- -------------------- ------------------------------- ------------------------------------- 1kilobits 1kb 2^10^ = 1,024 1024/8 = 128 1megabit 1mb 2^20^ = 1,048,576 1048576/8 = 131,072 1gigabit 1gb 2^30^ = 1,073,741,824 1073741824/8 = 134,217,728 1terabit 1tb 2^40^ = 1,099,511,627,776 1099511627776/8 = 137,438,953,472 1Kilobyte 1KB 8 x 2^10^ = 8,192 8192/8 = 1,024 1Megabyte 1MB 8 x 2^20^ = 8,388,608 8388608/8 = 1,048,576 1Gigabyte 1GB 8 x 2^30^ = 8,589,934,592 8589934592/8 = 1,073,741,824 1Terabyte 1TB 8 x 2^40^ = 8,796,093,022,208 8796093022208/8 = 1,099,511,627,776 Table 1: The different units of information It is pertinent that you can comfortably transform one unit to the other. **Example 3:** Find the number of bytes in 7mb. To do this you will need to first find the number of bits in 7mb, which is 7 x 2^20^ = 7340032 bits. You then divide by 8 to find the number of bytes as 1 byte = 8 bits. Therefore, number of bits in 7mb = 7340032/8 = 917504 bytes. **Example 4:** A computer network has a download speed of 1MBps. What is the speed in mbps? Remember that B is for Bytes while b is used to represent bits. The given speed is therefore 1 Megabytes per second, and you are required to find the speed in megabits per seconds. Since 1 bytes is equivalent to 8 bits, 1MB = 8mb. Therefore the computer download speed of 1MBps is equivalent to 8mbps. **1.3 Basic Operations on Bits** During processing, a computer manipulates the bits to give a desired result. This manipulation can be a complex process comprising of basic simple operations on the bits. In this section, you will learn how to carry out basic operations of addition, subtraction, division, multiplication of bits and logical operations on bits. **Addition of Bits** The addition of bits is similar to the addition of decimal numbers, just that a 2 is treated as a 10, and 1 added to the next bit on the left. The steps you will follow to add to bits together are outlined: Step 1: Align the bits to be added to the right Step 2: Start by adding the bits to the far right column Step 3: Add the bits in each column together, using the rule (1+0 = 1, 0+0 = 0, 1+1=0 add 1 to the next column) Binary addition Binary no 1 Binary no 2 Addition Carry ------------- ------------- ---------- ------- 0 0 0 0 1 0 1 0 0 1 1 0 1 1 0 1 Example 5: Add this two bits 10010010~2~ and 11010111~2~ 10010010 \+ 101101001~2~ Example 6: Find the sum of these bits 10111001~2~,110101~2~, 10110~2~ 10111001 -1^st^ Bits \+ -2^nd^ Bits 11101110 -Sum of 1^st^ and 2^nd^ Bits \+ -3^rd^ Bits 100000100~2~ -Sum of 1^st^, 2^nd^ and 3^rd^ Bits **Subtraction of Bits** The subtraction of bits is achieved by adding the 2's complement the number to be subtracted to the other bit. The procedure for obtaining the 2's complement is: Turn all the 0 to 1, and the 1 to 0, Add 1 to the last bit on the right. After getting the complement, add to the other binary, but ignore any overflow bit. Overflow bit is the extra bit to the left after the addition. Binary subtraction Binary no 1 Binary no 2 Subtraction Borrow ------------- ------------- ------------- -------- 0 0 0 0 1 0 1 0 0 1 1 1 1 1 0 0 Example 7: Find 1100 -- 1001 Step 1: Find the 2's complement of 1001. Flipping all bits gives 0110 Step 2: Adding 1100 to the complement 0110. 1100 \+ 0010 0011 **Recall:** if there is a carry add the carry to the least significant bit Therefore 1100 -- 1001 = 0011. Example 8: Find 11001 -- 1110 Step 1: Find the 2's complement of 01110. Note that it was padded with a 0 to make it equal in length to 11001. Flipping all bits gives 10001 Step 2: Adding 11001 to the complement 10001. 11001 \+ 01010 [ ] 01011 **Recall:** if there is a carry add the carry to the least significant bit The last bit to the left is the overflow bit, which is ignored after the addition. Therefore 11001 -- 1110 = 1011. It can observed that the bit after the overflow bit in the two examples are 0. This indicates that the result is a positive number. If it is 1, then the result is a negative number. The following example demonstrates this result of getting a negative result. Example 9: Find 10010 -- 11001. Step 1: Find the 1's complement of 11001. Flipping all bits gives 00110 Step 2: Adding 10010 to the complement 00110. 10010 11000 Step 3 : Since the resultant does not have a carry then flip the resultant and add a negative sign(i.e find the 1's complement of the result which gives -00111 so final answer 10010-11001=-00111 **Division of Bits** The division of bits is done by a series of subtractions of the divisor from the dividend, noting the remainder which is added to the other bits of the dividend. To achieve this, the following steps should be followed: Step 1: Align the non-zero most significant bits of the divisor and the dividend. Step 2: Subtract the divisor from the most significant bits of the dividend Step 3: if a borrow was needed, then the quotient/result is 1, and is 0 if no borrow was needed. Step 4: If a borrow was needed in step 4, add the divisor to the result of the subtraction to restore the dividend and drop the next significant bit. If no borrow was needed in the subtraction, just drop the next most significant bit to the result of the subtraction. Step 5: Repeat steps 2 -- 4 until all the bits of the dividend have been dropped down and the divisor subtracted and the quotient updated. The quotient and remainder after the last bit is dropped is returned as the result of the division. Example: find 01111100 / 0010 Here the dividend is 01111100 and the divisor is 0010 Remove the zero's in the most significant bit in both the dividend and divisor that doesn't change the value of the number 111110 10 1111100 10 11 10 **11** **10** **11** **10** **10** **10** **0** **Multiplication of Bits** The multiplication of binary number can be achieved by a series of shifting and addition. This can be achieved by following these steps Step 1: The numbers to multiplied are aligned to the left Step 2: The first bit to the left of the second number is used to multiply through all the bits of the first number. Here 1 x 0 = 0, 0 x 1 = 0, 1 x 1 = 1. Step 3: You then multiply the second bit of the second number through all the bits of the first, shift the result one bit to the right, and place below the result of step 1. Step 4: Keep multiplying through until all the bits of the second number have multiplied the bits of the first number. Step 5: Sum together the results of the multiplication of each bits Binary multiplication Binary no 1 Binary no 2 multiplication ------------- ------------- ---------------- 0 0 0 1 0 0 0 1 0 1 1 1 Example: Multiply 101101 x 10101 101101 X 101101 000000 101101 000000 \+ [101101 ] 1110110001 **Number Bases and Types** **1.0 Introduction** In the previous unit, the bit was introduced to be the shortened form of the binary digit that can exist is two states, 1 and 0. This can be referred to as a base two number. The base of a number refers to the number of numerals or states that the number can contain. The common bases that are used to represent data to the computer system are the base 2 (binary), base 10 (decimal) and base 16 (hexadecimal). This unit will be focusing on the binary, decimal and hexadecimal number bases and the types of numbers. **1.1 Binary Numbers (Base two)** As previously explained, a base two number can only exist in two states, 0 and 1. Each of the numeral is referred to as a bit. Series of bits put together to represents data that have more than two states. Table 2.0 shows a string of four bits (known as a nibble, half of a byte) and the decimal equivalent of the various states. **State** **Binary** **Decimal Equivalent** ----------- ------------ ------------------------ 1 0000 0 2 0001 1 3 0010 2 4 0011 3 5 0100 4 6 0101 5 7 0110 6 8 0111 7 9 1000 8 10 1001 9 11 1010 10 12 1011 11 13 1100 12 14 1101 13 15 1110 14 16 1111 15 A string of 4 bits can be used to represent 16 states of information to the computer system. This is from the fact that 2^3^ = 16. The base is raised to power 3 because counting the number of bits from 0 (for the least significant bit) to 3 for the most significant bit. As such each bit in base two have a value that depends on its position in the binary stream. **Power of Base** 3 2 1 0 **Decimal Equivalent** ------------------- --- --- --- --- -------------------------------------------- **Binary Number** 1 1 1 1 1 x 2^3^+ 1 x 2^2^+1 x 2^1^+ 1 x 2^0^ = 15 1 0 1 0 1 x 2^3^+ 0 x 2^2^+1 x 2^1^+ 0 x 2^0^ = 10 0 1 1 0 0 x 2^3^+ 1 x 2^2^+1 x 2^1^+ 0 x 2^0^ = 6 As table 2.1 shows, conversion of binary numbers to decimal numbers involves numbering the bits from 0 for the least significant to most significant. The value of the bit is then used to multiply the base raised to power of the base. The higher the number of bits in the system, the greater the amount of states and then data that can be fed into the computer, processed and stored. Example: Convert 11001010 to a decimal. How many states of information can a byte contain? In the solution, a conversion table is filled and worked out **Power of Base** 7 6 5 4 3 2 1 0 **Decimal Equivalent** ------------------- --- --- --- --- --- --- --- --- ------------------------------------------------------------------------------------- **Binary Number** 1 1 0 0 1 0 1 0 1 x 2^7^+ 1 x 2^6^+0 x 2^5^+ 0 x 2^4^ + 1 x 2^3^+ 0 x 2^2^+1 x 2^1^+ 1 x 2^0^ = 203 For the number of states, all the bits are set to 1, that is 11111111 and when converted to decimal gives 255, but 1 is added to the 255 to compensate for the 0 state to give 256 states. **1.2 Decimal Numbers (Base 10)** Decimal numbers are the most common base that are used to represent data input to computers and the output of processing are usually in decimals. This base has ten states/numerals ranging from 0 to 9. The position of the numeral also determines its value. The position 0 is referred to as unit, position 1 as tens, 2 as hundreds, 3 as thousands. For example the number 529 has 9 units, 2 tens and 5 hundreds all added together. Since this base is quite common, much explanations will not be necessary, but the conversion of base 10 to base 2 will be concentrated upon. The conversion of a base 10 to base 2 involves series of division of the base 10 number by 2, recording the remainders from bottom to top yields the base 2 number. As an example, let's work out the conversion of 105~10~ to base 2. Divide Remainder 2 105 --- ----- --- 2 52 1 2 26 0 2 13 0 2 6 1 2 3 0 2 1 1 0 1

Use Quizgecko on...
Browser
Browser