0% found this document useful (0 votes)
6 views

Data Representation

Uploaded by

Rudra ks
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Data Representation

Uploaded by

Rudra ks
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

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`.

• Signed Binary Numbers:


• Represent both positive and negative integers.
• Common formats include:
• Two's Complement: A popular method for representing signed integers.
• Example: `-5` in 4-bit two’s complement is `1011`.

• 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.

• ASCII (American Standard Code for Information Interchange): Represents each


character with a 7- or 8-bit code.
• Example: The letter `A` in ASCII is represented by `01000001` (65 in decimal).

• Unicode: A more comprehensive standard that supports a wider range of


characters (e.g., international characters, emojis) using up to 32 bits.
• Example: The character `अ` in Unicode is represented by `0905` (in hexadecimal).
Key types - Image Representation
Image Representation:
• Bitmap:
• Images are represented as grids of pixels, where each pixel is assigned a
specific binary value representing its color.
• Example: A black-and-white image uses 1 bit per pixel (0 for black, 1 for
white).
• Color Images:
• Use more bits per pixel, often in formats like RGB (Red, Green, Blue), where
each color channel uses 8 bits (resulting in 24 bits per pixel).
• Vector Images: Represent images using mathematical formulas instead of
pixels, useful for graphics that need to be scaled without losing quality.
Key types - Sound Representation
Sound Representation:
• Digital Sound:
• Represented by sampling sound waves at regular intervals and converting those samples
into binary values. This process is called pulse code modulation (PCM).
• The quality of the sound depends on the sampling rate (samples per second) and bit
depth (number of bits per sample).
• Example: A CD-quality audio is typically sampled at 44.1 kHz with a 16-bit depth.
Key types - Video Representation
Video Representation:
• Video is represented as a sequence of images (frames), each frame typically
being a bitmap image.
• These frames are displayed at a specific frame rate (e.g., 30 frames per
second).
• Compression methods like MPEG(Moving Picture Experts Group) reduce the
size of video files by storing differences between consecutive frames rather
than each frame individually also known as inter-frame compression.
Key types - RLE Representation
• Run-Length Encoding (RLE)
• Definition: A simple form of data compression where consecutive repeating
values (or runs) are replaced by a single value and a count. For example,
AAAABBBCCDA would be stored as 4A3B2C1D1A.
• Use Case: Used in image and video compression formats like BMP or TIFF to
reduce file sizes without losing information.
Key types – Huffman coding
• Huffman Coding
• Definition: A compression technique that assigns shorter binary codes to
more frequently occurring symbols and longer codes to less frequent
symbols. It’s a form of variable-length coding.
• Use Case: Often used in lossless data compression algorithms, such as ZIP files
and JPEG images.
Key types - Other Representation
Other Representations:
• Boolean Data: Represents true or false values using 1 (true) and 0
(false).
• Hexadecimal Representation: Often used as shorthand for binary,
with each hexadecimal digit representing four binary bits.
• Example: The binary number `1010 1100` is represented in hexadecimal as
`AC`.
Binary arithmetic addition
• Binary arithmetic addition is the process of adding two binary numbers
(numbers represented in base 2) to produce a sum. Here's how it works:
• Align the two binary numbers to be added, with the least significant bits
(rightmost bits) lined up.
• Add the corresponding bits of the two numbers, starting from the
rightmost bit.
• If the sum of the bits is 0 or 1, write down the result.
• If the sum of the bits is 2 (10 in binary), write down 0 and carry over the 1
to the next most significant bit.
• Repeat steps 3 and 4 for each bit position, moving leftward.
• If there is a carry over from the most significant bit, write it down as the
most significant bit of the result.
Binary arithmetic addition
• Here's an example of binary arithmetic addition:
• 1010 (10 in decimal)
• 1100 (12 in decimal)
------
10010 (22 in decimal)
• In this example, we add the corresponding bits of the two numbers, starting from the
rightmost bit. The sum of the bits is calculated, and if it's 2 (10 in binary), we write down
0 and carry over the 1 to the next most significant bit.
• Binary arithmetic addition is used in digital electronics and computer systems to perform
arithmetic operations. It's an essential concept in computer science and is used in
various applications, such as:
• Digital signal processing
• Image processing
• Data encryption
• Computer networking
Binary arithmetic subtraction
• Binary arithmetic subtraction is the process of subtracting one binary number from another. It's a
bit more complicated than binary addition, as it involves borrowing and carrying over bits. Here's
how it works:
• Align the two binary numbers to be subtracted, with the least significant bits (rightmost bits)
lined up.
• Subtract the corresponding bits of the two numbers, starting from the rightmost bit.
• If the subtrahend (bottom number) bit is 1, borrow from the next most significant bit.
• If the borrow is 1, subtract 1 from the next most significant bit and add 1 to the current bit.
• Repeat steps 2-4 for each bit position, moving leftward.
• If there's a final borrow, the result is negative (in two's complement representation).
• Some key things to remember:
• In binary subtraction, you can only subtract a smaller number from a larger number.
• If the subtrahend is larger than the minuend, the result will be negative.
• Two's complement representation is often used to simplify binary subtraction.
Binary arithmetic subtraction
• Let's see an example:
• 1010 (10 in decimal)
• 0110 (6 in decimal)
------
0010 (4 in decimal)
• In this example, we subtract the corresponding bits, borrowing and
carrying over as needed. The result is 0010, which represents 4 in
decimal.

You might also like