Data representation(computer science)

topic include:

~Binary and hexadecimal.
~Binary manipulation and negative numbers.
~How do computers represent text, images and sound.

~Measuring data storage.
~Data compression.

Binary and Hexadecimal

Hexadecimal : A base-16 number system that uses values (0-9) and characters (A-F).
Binary: A base-2 number system that uses the values 0 and 1.


Computers process, store, and communicate all data using discrete binary representations that can be scaled, calculated, and translated into human-readable media.

1. Binary and Hexadecimal
  • Binary (Base-2): A foundational numeral system using only two digits, 0 and 1. Each digit corresponds to a single bit, representing whether an electronic circuit is off (0) or on (1).

  • Hexadecimal (Base-16): A numbering system using sixteen symbols: 00 through 99 and letters A through F (where A = 10, B = 11, C = 1212, D = 13, E = 14, and F = 15).

    • Purpose: Acts as a human-friendly shorthand for long binary sequences; each hexadecimal digit directly represents a 4 bit4bit nibble (24=1624=16).

    • Common Uses: Memory addresses, MAC addresses, IPv6 configurations, and RGB colour codes.

    • Conversion: Group binary digits into blocks of 4 bits4bits starting from the right and map each block to its single hex equivalent.

2. Binary Manipulation and Negative Numbers
  • Binary Addition: Arithmetic addition following basic binary rules:

    • 0+0=0

    • 0+1=1

    • 1+0=1

    • 1+1=0(carry 1)

    • 1+1+1=1 (carry 1)

  • Overflow Error: Occurs when the result of a binary addition requires more bits than the allocated register can hold (e.g., an 8 bit8bit addition producing a 9 bit9bit value), causing the extra most significant bit to be dropped and producing an incorrect result.

  • Logical Shifts:

    • Logical Left Shift: Shifts all bits to the left by nn places, filling empty rightmost positions with 00. Effectively multiplies an unsigned integer by 2n2n.

    • Logical Right Shift: Shifts all bits to the right by nn places, filling empty leftmost positions with 00. Performs integer division of an unsigned integer by 2n2n.

  • Signed Negative Numbers:

    • Sign and Magnitude: Allocates the most significant bit (MSB) as the sign (00 for positive, 11 for negative) and the remaining bits for value magnitude. It introduces redundant representations (+0+0 and −0−0).

    • Two's Complement: The standard signed representation where the MSB has a negative place value (e.g., −128−128 for an 8 bit8bit integer). To convert a positive binary number to negative two's complement, invert every bit and add 11.

3. Representation of Text, Images, and Sound
  • Text:

    • Character Set: A defined table of characters recognizable by software and hardware, pairing each character with a distinct binary code.

    • ASCII: A 7 bit7bit standard capable of encoding 128128 characters (2727), covering the standard English alphabet, digits, punctuation, and control symbols.

    • Extended ASCII: An 8 bit8bit character set supporting 256256 characters (2828).

    • Unicode: A multi-byte system (using up to 32 bits32bits, commonly UTF-8) designed to represent over 1×1061×106 characters across world scripts, mathematical symbols, and emojis.

  • Images:

    • Bitmap: A digital image constructed from a two-dimensional grid of individual dots called pixels.

    • Resolution: The total number of pixels along the width and height of an image (e.g., 1920×10801920×1080).

    • Colour Depth: The number of bits assigned to encode the colour of each individual pixel. An image with a depth of n bitsnbits displays 2n2n possible colours.

    • File Size Formula:     Image File Size (bits)=width×height×colour depthImage File Size (bits)=width×height×colour depth

    • Metadata: Additional information stored within the file header, containing attributes such as image dimensions, colour depth, resolution, file type, and capture date.

  • Sound:

    • Analogue-to-Digital Conversion (ADC): Translates continuous sound waves into binary by capturing periodic amplitude measurements (sampling).

    • Sample Rate: The number of sound samples captured per second, measured in Hertz (HzHz).

    • Sample Resolution (Bit Depth): The number of bits allocated to represent the amplitude of each sound sample.

    • File Size Formula:     Sound File Size (bits)=sample rate×sample resolution×duration (s)×channelsSound File Size (bits)=sample rate×sample resolution×duration (s)×channels

4. Measuring Data Storage
  • Standard Units of Storage:

    • Bit (bb): The smallest unit of data, holding either 00 or 11.

    • Nibble: A cluster of 4 bits4bits.

    • Byte (BB): A collection of 8 bits8bits.

    • Kilobyte (KBKB): Equal to 1000 bytes1000bytes (103 bytes103bytes) in metric measurement, or a Kibibyte (KiB=1024 bytesKiB=1024bytes) in binary measurement.

    • Megabyte (MBMB): Equal to 1000 KB1000KB (1×106 bytes1×106bytes).

    • Gigabyte (GBGB): Equal to 1000 MB1000MB (1×109 bytes1×109bytes).

    • Terabyte (TBTB): Equal to 1000 GB1000GB (1×1012 bytes1×1012bytes).

    • Petabyte (PBPB): Equal to 1000 TB1000TB (1×1015 bytes1×1015bytes).

5. Data Compression
  • Compression: The process of encoding data using fewer bits than the original file to reduce storage requirements and decrease transmission times over networks.

  • Lossy Compression:

    • Definition: Permanently discards data that is less perceptible or redundant to the human ear or eye.

    • Characteristics: Achieves significant reductions in file size, but the original file cannot be restored exactly. Common formats include JPEG, MP3, and MP4.

  • Lossless Compression:

    • Definition: Reduces file size by identifying and removing statistical redundancy without discarding any original data.

    • Characteristics: Decompresses into an exact bit-for-bit duplicate of the original data. Yields lower compression ratios than lossy methods. Common algorithms include Run-Length Encoding (RLE) and Huffman coding; standard formats include PNG, ZIP, and FLAC.