Computers fundamentally operate using the binary number system, which uses only two digits: 0 and 1. However, humans commonly use the decimal system, which uses ten digits: 0 through 9. To bridge this gap, computers need to convert and represent decimal numbers in a way that they can process while maintaining a format that is understandable to humans.
In computing, decimal numbers can be represented in several ways:
Binary-Coded Decimal (BCD) is a method of representing decimal numbers where each digit of the decimal number is represented by its own binary sequence. This means that each decimal digit from 0 to 9 is converted to its four-bit binary equivalent.
Example: Representing 93 in BCD
So, 93 in decimal is represented as 1001 0011 in BCD.
Floating-point representation is used to represent real numbers (numbers with fractional parts). It allows for a very wide range of values by using scientific notation. A floating-point number is typically represented in computers using the IEEE 754 standard, which divides the number into three parts:
Example: Representing 9.3 in IEEE 754 single precision
So, 9.3 in IEEE 754 single precision is represented as: 0 | 10000010 | 00101001100110000000000
For representing decimal digits as characters, computers use character encoding schemes like ASCII (American Standard Code for Information Interchange). In ASCII, each decimal digit is assigned a unique 7-bit binary code.
Example: Representing '9' in ASCII
So, the character '9' is represented as 0111001 in binary in ASCII.