Binary and Decimal Integers
Data is expressed in terms of 0 and 1 known as bits. Different number systems are used to represent numbers. For example, decimal, octal and hexadecimal number systems, can be used. The decimal system uses ten different symbols from 0 to 9, octal uses 0 to 7, hexadecimal from 0 to 9 and further from A to F. We can convert from one number system to another. To convert a decimal number to binary, the double dabble method is used. In this method, the decimal number is divided by 2 and remainders are listed in reverse direction. The binary number obtained from this method is the equivalent of the decimal.
For example, the equivalent binary representation of 5 is 101. This is explained as follows:
The power of two (weights) and binary bits are multiplied and the sum of all multiplications is taken to give the equivalent decimal number.
In this method, a positive integer is converted to negative by changing each bit to its opposite value. For example, the binary number 0101 represents 5 and its complement is 1010.
In this method, 1 is added to the representation of one's complement. For example, 7 is represented as 0111 with an unsigned number. With two's complement, the number 7 becomes 1001 (One's complement of 0111 = 1000 and 1 is added at its least significant position giving a result of 1001).
Binary Coded Decimals
In addition to the binary number system, the programmer can also use decimal numbers. For example, a string of bits can be used to represent integers in the decimal number system. The decimal number from 0 to 9 can be represented using only a four-bit combination. Table 1.4 shows the decimal number and their equivalent binary digits.
A string of bits can be broken randomly into separate groups of four bits. Each group represents a digit. For example, the bit string 01100010 can be separated into two strings 0110 and 0010. The first string indicates six and the second two. The complete string represents 62. This method of representation is called as binary coded decimal.