Binary Representation
Binary Representation
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
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 Signal
Analog Signal
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 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
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
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
Number then normalized so that first significant digit is immediately to the right of the binary point
Example: .10111 x 23
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
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
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
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
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
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
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
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
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
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
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
= = = =
= = = =
Hexadecimal 34 2B 31 35
= = = =
Decimal 52 43 49 53
or 34162B1631163516
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
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.
0A 09 7F 00
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
001 DLE DC1 DC2 DC3 DC4 NAK SYN ETB CAN EM SUB ESC FS GS RS US
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.
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.
d2534
d2503
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.
Color
black
255 0 255 0 82 0
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.
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)