Data Representation
Data Representation
Computer codes
• Computer codes are the foundation of modern computing.
• Computer codes are sets of instructions that a computer can understand and execute. They are written in
programming languages, such as:
• Binary code: 0s and 1s that represent machine-specific instructions.
• Assembly language: Symbolic representation of binary code, using mnemonics and labels.
• High-level languages: Easy-to-read languages, like C++, Java, Python, and JavaScript.
• Scripting languages: Interpreted languages, like Perl, Ruby, and PHP.
• Markup languages: Used for formatting data, like HTML, XML, and CSS.
• Computer codes are used for:
• System programming: Operating systems, device drivers, and firmware.
• Application programming: Software applications, like word processors and games.
• Web development: Building websites, web applications, and mobile apps.
• Data analysis: Statistics, machine learning, and data visualization.
• Artificial intelligence: Machine learning, natural language processing, and computer vision.
• Computer codes are created using various tools, such as:
• Text editors: Notepad, Vim, and Emacs.
• Integrated development environments (IDEs): Visual Studio, Eclipse, and NetBeans.
• Compilers: Translate high-level languages into machine code.
• Interpreters: Execute high-level languages directly, without compilation.
• Computer codes have revolutionized the way we live, work, and communicate. They enable us to:
• Automate tasks
• Process data
• Create software applications
• Build websites and apps
• Advance artificial intelligence
Number systems
• Computers use the binary number system, which is a base-2 number system that
uses only two digits: 0 and 1. This is because computers are made up of
electronic switches that can be either on (1) or off (0).
• Binary Number System: Uses only 2 digits - 0 and 1.
• Decimal Number System: Uses 10 digits - 0 through 9.
• Hexadecimal Number System: Uses 16 digits - 0 through 9 and A through F (which represent
10 through 15).
• Octal Number System: Uses 8 digits - 0 through 7.
• The binary number system is used because it can be easily represented using
electronic switches, making it ideal for computer systems. The other number
systems are used for convenience and ease of use in programming and data
representation.
• Here are some key aspects of number systems in computers:
• Bit: A single binary digit (0 or 1).
• Byte: A group of 8 bits (can represent 256 values).
• Word: A group of 16 bits (can represent 65,536 values).
• Dword: A group of 32 bits (can represent 4,294,967,296 values).
• Understanding number systems is crucial in computer science, as it allows
programmers and computer scientists to represent and manipulate data
efficiently.
Data representation
• Data representation in computers refers to how data is stored,
processed, and communicated using binary (1s and 0s).
• Computers use different methods to represent various types of data,
such as text, numbers, images, and sound, in binary form because
they operate using digital signals that have two states
• on (1) and off (0).
Key types – Binary representation
• Binary representation
• The fundamental way computers represent data is through the binary
number system, which uses only two digits: 0 and 1.
• Each digit in a binary number is called a **bit**.
• A byte consists of 8 bits (e.g., 10110101).
• Each bit can represent two possible states, so a byte can represent 256
different values (2^8).
Key types – Octal representation
• Octal Representation
• Octal (Base 8): A number system that uses digits 0-7.
• It is sometimes used as a shorthand for binary because each octal digit
corresponds to exactly three binary digits.
• For example, the binary number 101110 as 56 in Octal.
• Use Case: Used in some programming and computer systems for simplifying
the representation of binary data.
Key types - Number Representation
Number Representation:
• Unsigned Binary Numbers:
• Represent positive integers using only bits.
• Example: The number `5` is represented in binary as `0101`.
• Floating-Point Numbers:
• Used to represent real numbers (fractions, decimals) and use a method similar to scientific
notation, with a mantissa and an exponent.
• Example: In binary floating-point, the number `6.5` might be represented as `1.101 × 2^2`.
Key types – Two’s complement
• Two's Complement
• Definition: A binary representation used to represent signed integers where negative numbers are obtained by inverting the bits of a positive
number and adding 1. For example, the number -5 is represented as the two's complement of 5.
• Use Case: This method simplifies arithmetic operations like addition and subtraction of signed integers in binary.
• In Two's complement:
• Positive numbers are represented as usual binary numbers
• Negative numbers are represented by flipping the bits of the corresponding positive number and adding 1
• For example:
• +5 in binary is 00000101
• -5 in binary is 11111011 (flip the bits and add 1)
• Two's complement has several advantages:
• Easy to implement in digital circuits
• Allows for simple arithmetic operations
• Can represent both positive and negative numbers
• It's widely used in computer systems, embedded systems, and digital electronics.
• Step-by-step process to calculate the Two's complement of a binary number:
• Start with the binary representation of the number
• Invert the bits (0 becomes 1, and 1 becomes 0)
• Add 1 to the inverted result
• For example, to calculate the Two's complement of 00000101 (+5):
• Invert the bits: 11111010
• Add 1: 11111011 (-5)
• Two's complement is an essential concept in computer science and digital electronics, as it allows for efficient representation and
manipulation of signed numbers in binary systems.
Key types - Unicode Representation
• Unicode
• Definition: A comprehensive character encoding system that assigns a unique
code to every character, symbol, and emoji across different languages and
platforms. Unicode can represent over a million unique characters.
• Use Case: Used in modern applications to ensure compatibility across global
languages and special characters.
Key types - Character Representation
Character Representation:
• Characters (letters, symbols) are represented using standardized encoding
schemes.