Resources | Subject Notes | Computer Science | Lesson Plan
This section explores how data is represented in binary form, which is fundamental to how computers store and process information. We will cover various number systems and their conversions.
Computers primarily use the binary number system. However, we often need to represent numbers in other systems, such as decimal, octal, and hexadecimal. Understanding the relationships between these systems is crucial.
Binary is the fundamental language of computers. It uses only two digits: 0 and 1. Each digit is called a bit.
Decimal is the number system we use in everyday life. It uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Each position in a decimal number represents a power of 10.
Octal uses eight digits: 0, 1, 2, 3, 4, 5, 6, 7. Each position in an octal number represents a power of 8.
Hexadecimal uses sixteen digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F, where A=10, B=11, C=12, D=13, E=14, and F=15. Each position in a hexadecimal number represents a power of 16.
We can convert between different number systems using various methods.
To convert a binary number to decimal, multiply each bit by the corresponding power of 2 and sum the results.
Example: $1011_2 = (1 \times 2^3) + (0 \times 2^2) + (1 \times 2^1) + (1 \times 2^0) = 8 + 0 + 2 + 1 = 11_{10}$
To convert a decimal number to binary, repeatedly divide the number by 2 and record the remainders. The remainders, read in reverse order, form the binary equivalent.
Example: $25_{10}$
Reading the remainders in reverse order gives $11001_2$
To convert binary to hexadecimal, group the binary digits into groups of four, starting from the right. Then, convert each group of four binary digits to its hexadecimal equivalent.
Example: $11010110_2$
$1101 \ 0110_2 = D \ 6_{16}$
To convert hexadecimal to binary, convert each hexadecimal digit to its four-bit binary equivalent and concatenate the results.
Example: $2A_ {16}$
$2_{16} = 0010_2$
$A_{16} = 1010_2$
$2A_{16} = 0010 \ 1010_2 = 101010_2$
To convert decimal to hexadecimal, repeatedly divide the number by 16 and record the remainders. The remainders, read in reverse order, form the hexadecimal equivalent. If a remainder is 10, 11, 12, 13, 14, or 15, it is represented by A, B, C, D, E, or F, respectively.
Example: $25_{10}$
$25_{10} = 19_{16}$
In a computer, data is typically stored as binary. Different data types are represented using specific numbers of bits.
Data Type | Size (bits) | Range | Example |
---|---|---|---|
Byte | 8 | 0 to 255 | Any character, small integer |
Half-Byte (Nibble) | 4 | 0 to 15 | Represents a part of a character |
Word | 16 | 0 to 65535 | Larger integer, address |
Double Word | 32 | 0 to 4294967295 | Large integer, memory address |
Characters and other symbols are encoded into binary using various encoding schemes. A common example is ASCII (American Standard Code for Information Interchange), which uses 7 bits to represent 128 characters.
Other encoding schemes include Unicode, which supports a wider range of characters.