You are on page 1of 52

Binary Representation

1. Binary Representation: the power of 0 and 1 2. Data Storage: how to record 0 and 1 3. Logic Table and Circuit: how to process 0 and 1

Computing Systems Data


Usually the computing systems are complex devices, dealing with a vast array of information categories The computing systems store, present, and help us modify: Numbers Text Audio Images and graphics Video

Digital vs. Analog


Computing systems are finite machines. They store a limited amount of information, even if the limit is very big.
The goal, is to represent enough of the world to satisfy our computational needs and our senses of sight and sound.

The information can be represented in one or two ways: analog or digital.


Analog data is a continuous representation, analogous to the actual information it represents.
In example, a mercury thermometer is an analog device. The mercury rises in a continuous flow in the tube in direct proportion to the temperature.

Digital data is a discrete representation, breaking the information up into separate (discrete) elements.
Computers cant work with analog information, so a need do digitize the analog information arise. This is done by breaking the analog information into pieces and representing those pieces using binary digits

Digital vs. Analog


Both electronic signals (analog and digital) degrade as they move down a line. The voltage of the signal fluctuates due to environmental effects. As soon as an analog signal degrades, information is lost. Since any voltage level within the range is valid, it is impossible to know that the original signal was even changed Digital signals jump sharply between two extremes (high and low state). A digital signal can degrade quite a bit until the information is lost, because any value over a certain threshold is considered high value and bellow the threshold is considered low value

Digital vs. Analog


One can still retrieve the information from a reasonably degraded digital signal Periodically a digital signal is reclocked to regain its original shape. As long as it is reclocked before too much degradation, no info is lost.
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 Threshold 0

Digital Signal

Digital Signal Degradation

Analog Signal

Analog Signal Degradation

Binary representation of Computer Memory


Every piece of information stored on computer is encoded as combination of ones and zeros. These ones and zeros are called bits. Physical Hardware Implementation Any system that has two states can be thought of as a bit: Detecting Voltage Levels High / Low
[Why not 10 levels? Would be unreliable/Not enough difference between states]

Switching On / Off Fully Charged - Fully Discharged - Using electronic charges (CCD for pictures) Magnetized Demagnetized (Hard Disk) On papers with holes (punch card) On papers with inks (scantron) Storing data as pits or lands (CD-ROM) - differences in reflected light to optically read them One byte is a sequence of eight consecutive bits. A word is some number, typically 4 (32 bit), recently 8 (64 bit) of consecutive bytes.

Using Magnetic Cores to Represent Binary Values (e.g. Hard Disk)

Using Transistor Switching to Represent Binary Values (e.g. CPU, RAM, Flash Disk)
Transistors A semiconductor device used to switch and amplify electronic signals Transistors form switches that are in on or off states. The Pentium 4 chip has over 42 million, Core 2 Duo has over 291 million and 6-core Core-i7 has over 1.2 billion transistors. Each transistor creates one bit. Simplified Model of a Transistor

Using Optical Principle to Represent Binary Values (e.g. CD/DVD)

Binary Representation of Numeric Information (Representing integers)


With a sequence of n bits, there are 2n unique representations The representation of a non-negative integer using binary, weighted positional notation is called unsigned integer representation Given n bits, it is possible to represent the range of unsigned integer values from 0 to 2n - 1 For example an 8-bit representation would allow representations that range 0 to 255

Given an n+1-bit sign magnitude number the range of signed integer values that it can represent is -(2n-1) to +(2n-1) For example an 8-bit representation would allow representations that range -127 to 128

Signed Integer
An extra bit in the most significant position is designated as the sign bit which is to the left of an unsigned integer. The unsigned integer is the magnitude.
x xxx xxxx

A 0 in the sign bit means positive, and a 1 means negative

Signed Integer
Sign magnitude representation associates a sign bit with a magnitude that represents zero, thus it has two distinct representation of zero: 00000000 and 10000000
sign bit magnitude

Binary representation
A single (unsigned) byte of memory

bit 7

bit 6

bit 5

bit 4

bit 3

bit 2

bit 1

bit 0

In decimal representation, this number is: 1*20 + 0*21 + 0*22 + 1*23 + 0*24 + 1*25 + 1*26 + 1*27 = 233

Binary representation
One bit must be used to store sign of number A single (signed) byte of memory +/bit 7 1 bit 6 1 bit 5 0 bit 4 1 bit 3 0 bit 2 0 bit 1 1 bit 0

In decimal representation, this number is: 1*20 + 0*21 + 0*22 + 1*23 + 0*24 + 1*25 + 1*26 = +/- 105

Binary Representation of Real Numbers


Representing real numbers
Real numbers may be put into binary scientific notation: a x 2b
Example: 101.11 x 20

Number then normalized so that first significant digit is immediately to the right of the binary point
Example: .10111 x 23

Mantissa and exponent then stored

Binary Representation Textual Information


Characters are mapped onto binary numbers ASCII code set American Standard Code for Information Interchange 8 bits per character; 256 character codes UNICODE code set (8/16/32 bit) 16 bits per character; 65,536 character codes Text strings are sequences of characters in some encoding

ASCII Features
7-bit code 8th bit is unused (or used for a parity bit) 27 = 128 codes Two general types of codes:
95 are Graphic codes (displayable on a console) 33 are Control codes (control features of the console or communications channel)

ASCII Table

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

000 NULL SOH STX ETX EDT ENQ ACK BEL BS HT LF VT FF CR SO SI

001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US

010 ! " # $ % & ' ( ) * + , . /

011 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

100 @ A B C D E F G H I J K L M N O

101 P Q R S T U V W X Y Z [ \ ] ^ _

110 ` a b c d e f g h i j k l m n o

111 p q r s t u v w x y z { | } ~ DEL

i.e. a = 11000012 = 9710 = 6116

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

000 NULL SOH STX ETX EDT ENQ ACK BEL BS HT LF VT FF CR SO SI

001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US

010 ! " # $ % & ' ( ) * + , . /

011 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

100 @ A B C D E F G H I J K L M N O

101 P Q R S T U V W X Y Z [ \ ] ^ _

110 ` a b c d e f g h i j k l m n o

111 p q r s t u v w x y z { | } ~ DEL

95 Graphic codes

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

000 NULL SOH STX ETX EDT ENQ ACK BEL BS HT LF VT FF CR SO SI

001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US

010 ! " # $ % & ' ( ) * + , . /

011 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

100 @ A B C D E F G H I J K L M N O

101 P Q R S T U V W X Y Z [ \ ] ^ _

110 ` a b c d e f g h i j k l m n o

111 p q r s t u v w x y z { | } ~ DEL

33 Control codes

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

000 NULL SOH STX ETX EDT ENQ ACK BEL BS HT LF VT FF CR SO SI

001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US

010 ! " # $ % & ' ( ) * + , . /

011 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

100 @ A B C D E F G H I J K L M N O

101 P Q R S T U V W X Y Z [ \ ] ^ _

110 ` a b c d e f g h i j k l m n o

111 p q r s t u v w x y z { | } ~ DEL

Alphabetic codes

Hello, world Example


H e l l o , w o r l d = = = = = = = = = = = = Binary 01001000 01100101 01101100 01101100 01101111 00101100 00100000 01110111 01101111 01110010 01101100 01100100 = = = = = = = = = = = = Hexadecimal 48 65 6C 6C 6F 2C 20 77 6F 72 6C 64 = = = = = = = = = = = = Decimal 72 101 108 108 111 44 32 119 111 114 108 100

Note: 12 characters requires 12 bytes Each character requires 1 byte

Example of Text Representation


Encoding Hello CDS 130

String broken to words, words broken to characters (bytes)

Example of Text Representation


Encoding Hello CDS 130

Characters to ASCII number

Example of Text Representation


Encoding Hello CDS 130

ASCII number to binary number

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

000 NULL SOH STX ETX EDT ENQ ACK BEL BS HT LF VT FF CR SO SI

001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US

010 ! " # $ % & ' ( ) * + , . /

011 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

100 @ A B C D E F G H I J K L M N O

101 P Q R S T U V W X Y Z [ \ ] ^ _

110 ` a b c d e f g h i j k l m n o

111 p q r s t u v w x y z { | } ~ DEL

Numeric codes

4+15 Example
4 + l 5

= = = =

Binary 00110100 00101011 00110001 00110101

= = = =

Hexadecimal 34 2B 31 35

= = = =

Decimal 52 43 49 53

4+15 is represented as 00110100 00101011 00110001 00110101

or 34162B1631163516

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

000 NULL SOH STX ETX EDT ENQ ACK BEL BS HT LF VT FF CR SO SI

001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US

010 ! " # $ % & ' ( ) * + , . /

011 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

100 @ A B C D E F G H I J K L M N O

101 P Q R S T U V W X Y Z [ \ ] ^ _

110 ` a b c d e f g h i j k l m n o

111 p q r s t u v w x y z { | } ~ DEL

Punctuation, etc.

Common Control Codes


CR LF HT DEL NULL

0A 09 7F 00

0D carriage return line feed horizontal tab delete null

0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111

000 NULL SOH STX ETX EDT ENQ ACK BEL BS HT LF VT FF CR SO SI

001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US

010 ! " # $ % & ' ( ) * + , . /

011 0 1 2 3 4 5 6 7 8 9 : ; < = > ?

100 @ A B C D E F G H I J K L M N O

101 P Q R S T U V W X Y Z [ \ ] ^ _

110 ` a b c d e f g h i j k l m n o

111 p q r s t u v w x y z { | } ~ DEL

Escape Sequences
Extend the capability of the ASCII code set For controlling terminals and formatting output Defined by ANSI in documents X3.41-1974 and X3.641977 The escape code is ESC = 1B16 An escape sequence begins with two codes: Example:
Erase display: Erase line: ESC [ 2 J ESC [ K

ESC

1B16

5B16

Unicode
The extended version of the ASCII character set is not enough for international use. The Unicode character set uses 16 bits per character. Therefore, the Unicode character set can represent 216, or over 65 thousand (65,536), characters. Unicode was designed to be a superset of ASCII. That is, the first 256 characters in the Unicode character set correspond exactly to the extended ASCII character set.

Three Unicode Encodings


UTF-16: 16-bit code units UTF-8: 8-bit code units UTF-32: 32-bit code units All have equal representation power All have advantages and disadvantages

Unicode
Version 2.1
1998 Improves on version 2.0 Includes the Euro sign (20AC16 = From the standard:

contains 38,887 distinct coded characters derived from the supported scripts. These characters cover the principal written languages of the Americas, Europe, the Middle East, Africa, India, Asia, and Pacifica.

Latest version of Unicode is 4.0


http://www.unicode.org

Unicode for Bengali


d2437 d2453

d2534

d2503

Binary Representation of Sound and Images


Multimedia data is sampled to store a digital form with or without detectable differences
Representing sound data
Sound data must be digitized for storage in a computer

Digitizing means periodic sampling of amplitude values

Binary Representation of Sound and Images

From samples, original sound can be approximated


To improve the approximation
Sample more frequently Use more bits for each sample value

Digitization of an Analog Signal

Sampling the Original Signal

Recreating the Signal from the Sampled Values

Audio Information Representation


Sound is perceived when a series of air compressions vibrate a membrane in our ear, which sends signals to our brain A stereo sends an electrical signal to a speaker to produce sound. This signal is an analog representation of the sound wave. The voltage in the signal varies in direct proportion to the sound wave To digitize the signal we periodically measure the voltage of the signal and record the appropriate numeric value. The process is called sampling In general, a sampling rate of around 40,000 times per second is enough to create a very good high quality sound reproduction

Audio Information Representation

Sampling an audio signal

Audio Formats
Several popular formats are: WAV, AU, AIFF, VQF, and MP3. Currently, the dominant format for compressing audio data is MP3. MP3 is short for MPEG-2, audio layer 3 file. Compressed formats usually employ both lossy and lossless compression. Analyzes the frequency spread and compares it to mathematical models of human psychoacoustics (the study of the interrelation between the ear and the brain) and it discards information that cant be heard by humans. Then the bit stream is compressed using a form of Huffman encoding to achieve additional compression.

Representing Images and Graphics


Color is our perception of the various frequencies of light that reach the retinas of our eyes Our retinas have three types of color photoreceptor cone cells that respond to different sets of frequencies. These photoreceptor categories correspond to the colors of red, green, and blue Color is often expressed in a computer as an RGB (redgreen-blue) value, which is actually three numbers that indicate the relative contribution of each of these three primary colors For example, an RGB value of (255, 255, 0) maximizes the contribution of red and green, and minimizes the contribution of blue, which results in a bright yellow

Representing Images and Graphics


The amount of data that is used to represent a color is called the color depth. HiColor is a term that indicates a 16-bit color depth. Five bits are used for representing the R and B components. Six bits are used for representing the G component, because the human eye is more sensitive to G; TrueColor indicates a 24-bit color depth. Therefore, each number in an RGB value is represented using eight bits.

Representing Images and Graphics


RGB Value Red Green Blue
0 0 0

Color
black

255 255 255 146 157 140

255 255 130 81 95 0

255 0 255 0 82 0

white yellow Pink brown purple maroon

Digitized Images and Graphics


Digitizing a picture is the act of representing it as a collection of individual dots called pixels. The number of pixels used to represent a picture is called the resolution. The storage of image information on a pixel-by-pixel basis is called a raster-graphics format. Several popular raster file formats including bitmap (BMP), GIF, and JPEG.

BMP Raster Image Example

The smiley face in the top left corner is a bitmap image. When enlarged, individual pixels appear as squares. Each pixel is described by a value for red, green and blue.

Vector Graphics
Instead of assigning colors to pixels as we do in raster graphics, a vector-graphics format describe an image in terms of lines and geometric shapes. A vector graphic is a series of commands that describe a lines direction, thickness, and color. The file size for these formats tend to be small because every pixel does not have to be accounted for. Vector graphics can be resized mathematically, and these changes can be calculated dynamically as needed. However, vector graphics is not good for representing realworld images.

Example of Vector Image


Effect of vector graphics versus raster graphics. Magnification of 7x as a vector image vs same magnification as a bitmap image. Examples of vector image formats: SVG (Scalable Vector Graphics), EPS (Encapsulated Post Script), etc..

Binary Representation of Sound and Images

Representing image data


Images are sampled by reading color and intensity values at even intervals across the image

Each sampled point is a pixel


Image quality depends on number of bits at each pixel

Hexadecimal representation
Memory addresses are always in terms of hexadecimal. Try printing any address in C: E.g: int x; printf (%x\n, &x); Result will be an hexadecimal address.

Example
# include <stdio.h>
int main () { int x; printf ("%x\n", &x); return 0; } Output: bffffbd4 (for example)

You might also like