Resources | Subject Notes | Computer Science
Computers are fundamentally based on electronic circuits that can be in one of two states: ON or OFF. These states are conveniently represented by the binary digits 0 and 1. This binary system is the foundation for how computers represent all types of data, including text, numbers, images, and sound.
Using binary offers several advantages for computers:
The binary number system is a base-2 system. Each position in a binary number represents a power of 2. From right to left, the positions represent $2^0$, $2^1$, $2^2$, $2^3$, and so on.
Example: The binary number 1011 is equal to ($1 \times 2^3$) + ($0 \times 2^2$) + ($1 \times 2^1$) + ($1 \times 2^0$) = 8 + 0 + 2 + 1 = 11 in decimal.
Text is represented using character codes. The most common character encoding standard is ASCII (American Standard Code for Information Interchange). ASCII assigns a unique numerical value to each character, including letters, numbers, punctuation marks, and control characters.
Each character is typically represented by 8 bits, forming a byte. The ASCII code for the letter 'A' is 65.
Character | ASCII Code |
---|---|
A | 65 |
B | 66 |
0 | 48 |
! | 33 |
Numbers can be represented in binary using different methods, depending on whether they are integers or floating-point numbers.
Integers: Integers can be represented directly in binary using a fixed number of bits. For example, an 8-bit binary number can represent numbers from 0 to 255.
Floating-Point Numbers: Floating-point numbers (like 3.14159) are represented using a more complex system called IEEE 754. This standard defines how to represent numbers with a limited number of bits, including a sign bit, an exponent, and a mantissa (fractional part).
Images are represented as a grid of pixels. Each pixel has a color value. The color value is typically represented using a combination of red, green, and blue (RGB) components. Each component is represented by a number, often 8 bits, allowing for 256 different shades.
An image can be stored as a series of binary numbers representing the color values of each pixel.
Sound is represented by a series of digital samples. A digital sample is a numerical representation of the sound's amplitude at a specific point in time. The amplitude is typically measured using a sampling rate (how many samples per second) and a bit depth (how many bits are used to represent each sample).
These samples are then converted into binary form for storage and processing.
Computers need to convert data between different representations. This involves encoding data into binary and decoding binary data back into its original form.
Encoding: Converting a decimal number to binary. This can be done using division by 2 and keeping track of the remainders.
Decoding: Converting a binary number to decimal. This involves multiplying each bit by the corresponding power of 2 and summing the results.
Binary is the fundamental language of computers. Understanding how data is represented in binary is crucial for understanding how computers store and process information. Different data types require different encoding schemes, but all are ultimately represented using sequences of 0s and 1s.