computer systems 2

ECS404: Computer Systems and Networks - Digital Representation

Week 2: Overview

  • Topics Covered: Integer representation, binary encoding, hexadecimal, and two's complement.

  • Learning Objectives:

    • Understand basic binary concepts: bits and bytes.

    • Learn the conversion between decimal, binary, and hexadecimal.

    • Understand two’s complement representation for signed integers.

      • Convert between binary two's complement and signed decimal.

      • Add and multiply in two's complement system.

      • Negate and test positivity for two's complement numbers.

Binary Representation

  • Binary uses bits (binary digits: 0s and 1s).

  • Byte: A group of 8 bits.

  • Examples:

    • 0000 0101 represents the number 5.

    • 1111 1011 can represent the number -5 in two's complement.

    • 0111 1000 represents both the letter x and the number 120.

    • Interpretation is context-dependent (e.g., same bit patterns can mean different values).

Conversion Methods

  • Binary can be converted to decimal and vice versa.

  • Hexadecimal: Used to represent binary in a compact form.

  • Key conversions include:

    • From binary to decimal using powers of 2.

    • From decimal to binary by breaking down the decimal number.

Two's Complement System

  • Two’s complement simplifies arithmetic with signed numbers.

  • Why Use Two's Complement?:

    • It eliminates the ambiguity of having two zeros (+0 and -0) as seen in sign and magnitude representation.

    • Using two's complement allows leveraging the same addition circuitry for both signed and unsigned integers.

  • To Negate a Two's Complement Number:

    • Invert bits and add 1.

Understanding Number Types

  • Whole Numbers: Positive and Negative (e.g., -3, -2, 0, 1, 2, 3).

  • Fractions: e.g., 1/4, -5/6.

  • Real Numbers: E.g., π ≈ 3.14159.

  • Complex Numbers: E.g., i.

Java Data Representations

  • Java's 8 Primitive Data Types:

    • byte: 8-bit signed two’s complement.

    • short: 16-bit signed.

    • int: 32-bit signed.

    • long: 64-bit signed.

    • float: 32-bit IEEE floating point.

    • double: 64-bit IEEE floating point.

    • boolean and void types are also included.

Endianness

  • Endianness Concepts:

    • Big Endian: High-order bytes come first.

    • Little Endian: Low-order bytes come first.

    • Most computers use Little Endian for internal representation, while network protocols often use Big Endian.

Summary of Key Concepts

  • Binary (base 2) is fundamental for computer systems.

  • Understanding bits, bytes, and how to convert between different representations is crucial for programming and computer science.

  • Arithmetic with integers can use similar algorithms across different systems by leveraging representations such as two's complement.