How do computers represent data as 0s and 1s and perform negative operations accurately?

H

Computers represent data as 0s and 1s, and use signed absolute value, 1’s complement, and 2’s complement to represent positive and negative numbers in 4 bits. Signed double precision is math imprecise, and base 1 suffers from the double representation of zero. The two’s complement solves these problems and provides rules for handling overflows to make the computation more accurate.

 

Computers represent data internally using bits represented by 0s or 1s as the smallest unit. There is a fixed number of bits that a computer can process at a time, called a word. For example, a 64-bit computer processes 64 bits in one word. To represent a positive integer on a computer with 4 bits per word, the most significant bit, which is the left-most digit of the 4 bits, is represented by a 0 to represent a positive number, and the remaining 3 bits represent the absolute value of the integer. In the case of 0111, the leftmost bit, ‘0’, represents a positive number, and the remaining ‘111’ is the binary representation of the integer’s absolute value of 7, which is +7. The remaining bits, except for the most significant bit, are called data bits.
However, when representing a negative integer, the most significant bit is represented as 1. To represent -3, we would add the most significant bit 1 to 011, which is the binary representation of the absolute value of -3. This way of representing negative numbers is called “signed double precision”. However, signed absolute values are imprecise math. For example, if you were to calculate 7-3, it would be represented as 0111+1011, which is 7+(-3). Since computers only use zeros and ones, adding a 1 to a 1 immediately raises the place value to 10. So 0111 plus 1011 equals 10010. 10010 is more than one word that a 4-bit computer can handle, a phenomenon known as overflow. In signed absolute values, the calculation is inaccurate because there is no special rule for handling overflow. Also, 0000 or 1000 represents zero, which is less consistent in representation and less efficient in storage.
Another way to represent negative integers is the “1’s complement” method. A complement is a number that is complementary to a number, such that the complement of n to any number a is the number whose sum with a is n. For example, the complement of 1 to 1 is 0, and the complement of 1 to 0 is 1. The way to represent negative numbers in base 1 is to represent the most significant bit as a 1 and the data bits as 1’s complement of each digit. A 1’s complement is a number that sums to 1 for each digit, so if -3 were represented in 1’s complement, the data bits would be 100, the 1’s complement of 011, which is the binary representation of -3’s absolute value of 3. Adding a 1 to the most significant bit to represent negative numbers gives us 1100. In the base-one method, a separate handling rule can be utilized in case of overflow to ensure that the computed value is correct. However, it cannot solve the problem of representing a zero when the computed value is 0000 or 1111.
To solve the problem of representing zero in two ways, the two’s complement method is used to represent negative numbers. The two’s complement method is represented as a one’s complement and then one is added to the data bits. To represent -3 in 2’s complement, you would find 100, a 1’s complement of 011, the binary representation of -3’s absolute value of 3, and then add 1 to 101, the most significant bit, to represent the negative number, to get 1101. Assuming a computer that processes 4 bits as 1 word, let’s compute 7-3 as a 2’s complement. To represent a positive integer, you don’t need to use either the 1’s complement or the 2’s complement, so 7-3 is 7+(-3), which is 0111+1101 in 2’s complement. Computing this yields 10100, which is overflowing by 4 bits. The 2’s complement rule requires us to discard the excess bits when an overflow occurs, resulting in 0100.
Computers process and represent data in a variety of ways, and efficiency and accuracy are important in this process. Complex math, especially when representing negative numbers, plays an important role in computer science. Signed absolute value, base 1, and base 2 each have their own advantages and disadvantages, and you should choose the appropriate method based on the actual application. Understanding these concepts will also give you a deeper understanding of how computers work. The way data is represented directly affects the performance and computational efficiency of a computer, and optimizing it is a major challenge. Computer scientists are constantly conducting research to solve these problems, and new methods and techniques are being developed. This research and development, along with advances in computer technology, has a huge impact on society as a whole.

 

About the author

Blogger

Hello! Welcome to Polyglottist. This blog is for anyone who loves Korean culture, whether it's K-pop, Korean movies, dramas, travel, or anything else. Let's explore and enjoy Korean culture together!