Understanding Data Representation
You've probably heard about bits and bytes, but what exactly are they?
Bit
The smallest unit of data in a computer, representing a binary value of 0 or 1.
The term bit is short for binary digit.
AnalogyA single bit can represent two states, such as on/off, true/false, or yes/no.
Byte
Fundamental unit of data storage, which consists of eight bits
Bits are usually denoted by lowercase b, but bytes by a capital B (1B = 8b).
Common Mistake- It's crucial not to confuse bits and bytes.
- For example, 12Mb (megabits) is not the same as 12MB (megabytes).
- Since 1 byte = 8 bits, 12 MB is eight times larger than 12Mb.
To effectively utilise such units, we use the binary numbering system (base 2).
Binary
Binary is a base-2 number system, using only two digits: 0 and 1. Each digit in a binary number is called a bit (short for binary digit).
All data and instructions in a computer are stored and processed in binary form.
Tip- When working with hexadecimal numbers (base 16), remember that each digit represents four bits (half of the byte).
- This makes it easy to convert between binary and hexadecimal.
The relationship between the number of bits and the number of possible representations is given by $2^n$, where $n$ is the number of bits.
Storage of Different Kinds of Data
Here are some interesting examples of how different entities are represented in binary and stored in memory.
Integers
We can distinguish two types of integers: unsigned and signed.
Unsigned integers:
- Use all 8 bits to represent non-negative values.
- Range: represents values from 0 to 255
$35$ can be stored as $00100011$.
Signed integers:
- Uses one bit for the storage of the sign and 7 remaining bits for the value.
- The most significant bit (MSB) (the leftmost bit) is used as a sign bit (0 for positive, 1 for negative).