Method of representing or encoding numbers Two main notation types Sign-value Roman numerals Positional (place-value) Modern decimal notation Several number systems are commonly used in computing Decimal Binary Hexadecimal “Shorthand” for binary Digital Data2
We count in “decimal” or base 10 by powers of 10: 10 0 = 1 10 1 = 10 10 2 = 10*10 = 100 10 3 = 10*10*10 = 1,000 10 6 = 1,000,000 Computers count in “binary” or base 2: 2 0 = 1 2 1 = 2 2 2 = 2*2 = 4 2 3 = 2*2*2 = 8 2 10 = 1,024 Digital Data3
Bit (b): binary digit -- 0 or 1 value 0 or 1 correspond to the electrical values of off or on, respectively All computer data is represented in bits Byte (B): grouping of 8 bits Considered the basic unit of digital information 8 bits = 1 byte is the de facto standard (also called an octet ) File sizes and network data are measured in bytes You can’t have a 5-bit file Physical network media transmit bits, but network protocols are based on bytes Unit multiples Kilobyte: 2 10 = 1,024 bytes (≈ 1,000) Megabyte: 2 20 = 1,048,576 bytes (≈ 1,000,000) Gigabyte: 2 30 = 1,073,741,824 bytes (≈ 1,000,000,000) Terabyte: 2 40 = 1,099,511,627,776 bytes (≈ 1,000,000,000,000) Digital Data4
Base (also called radix ) Number around which system is organized Number of symbols used to represent each digit of a number Digits Set of symbols used in forming numbers Additional symbols may be defined for bases > 10 Ex: hexadecimal (see chart at right) Positional Notation Position of a digit conveys its significance Rightmost digit represents the zero- power of the base value Moving left, each digit represents an increasing power of the base number Number SystemBaseDigits Decimal 100,1,…, 9 Binary 20, 1 Hexadecimal 160, 1,…, 9, A – F Digit Position Number System Decimal , , Binary Hexadecimal , , Digital Data5
Decimal Binary Hexadecimal Digit Position ( k ) 3210 Weight (b k ) Decimal Weight1, Digit (a k ) 2002 Decimal Value 2, = 2,002 Digit Position ( k ) Weight (b k ) Decimal Weight1, Digit (a k ) Decimal Value 1, = 2,002 Digit Position ( k ) 210 Weight (b k ) Decimal Weight Digit (a k ) 7D2 Decimal Value 1, = 2,002 Digital Data6
Hexadecimal used as shorthand notation for binary One hex digit represents four binary digits Hexadecimal numbers are usually prefixed with “0x” Tells someone reading the number it is a hex value 7D2 16 → 0x7D2 Digital Data7
8 DecimalBinaryHex DecimalBinaryHex A B C D E F
1. Divide the value by the given base x The remainder will be the least significant (right- most) digit of the base x number 2. Divide the result by the base The remainder becomes the most significant (left- most) digit of the base x number 3. Repeat step 2 until the result is zero The remainder is the most significant digit of the base x number Digital Data9
Convert the decimal value 150 to binary What decimal value does the bit pattern Convert the binary pattern To hex Digital Data10
Convert 2,016 to binary (base 2) Convert 2,016 to hexadecimal (base 16) 7 / 16 =0remainder / 16 =7remainder E (14) 2,016 / 16 =126Remainder 0 Digital Data 11 1 / 2 =0remainder 1 3 / 2 =1remainder 1 7 / 2 =3remainder 1 15 / 2 =7remainder 1 31/ 2 =15remainder 1 63 / 2 =31remainder / 2 =63remainder / 2 =126remainder / 2 =252remainder 0 1,008 / 2 =504remainder 0 2,016 / 2 =1,008remainder 0 Binary Digits Left to Right = = 7E0 16 Hex Digits Left to Right
American Standard Code for Information Interchange (ASCII) Character-encoding scheme based on the ordering of the English alphabet Maps digital bit pattern and character symbol Includes Printable characters Alphabet, numbers, symbols Graphics characters ■ ┌ ┐ ╔ ╗ Control characters Backspace, tab, line feed, carriage return Many of these characters are non-printable Digital Data12
Digital Data13
Strings are a sequence of bytes Bytes represent ASCII characters Characters can be represented as Character value: ‘m’ Decimal value: 109 Hexadecimal value: 0x6d Try entering these URLs in a browser ‘%’ tells the program what follows is a hex value Digital Data14
A file is a collection of binary data Format determines the interpretation of bit patterns Specifies the type of data a file contains Text, image, sound, Word, Excel, etc. Example USA (ASCII text file) (24-bit bitmap) Digital Data15
Executable programs are just files Sequence of bytes Computers interpret the byte sequence as instructions Executable file formats Windows – Portable Executable (PE) format .exe,.dll (libraries),.sys (device drivers) UNIX – Executable and Linkable Format (ELF) Also used by UNIX variants Linux, BSD, Solaris Mac OS X – Mach object file (Mach-O) Earlier Mac OSs use Preferred Executable Format (PEF) Digital Data16
Convention for naming files . Extension is usually three letters .txt (text),.jpg (JPEG image),.mp3 (MP3 audio),.doc (Word),.xls (Excel) Can be more or less .c (C source code),.gz (GNU zip),.docx (Word),.xlsx (Excel) Extension DOES NOT determine bit interpretation Determined by file format Operating systems and applications make decisions based on file extension .doc *ought* to be a Word document…I should use Microsoft Word to open it Extensions can be changed without changing the file format Example: change.zip to.txt to a ZIP file Can still open the “.txt” file with a program that recognizes the ZIP file format Digital Data17
What string is represented by the ASCII values : What exactly is displayed when we open the file yay.txt in notepad which consists of the following bytes: What exactly would be displayed in Frhed when we open yay.txt? Digital Data18
Number Systems Decoded detail.asp?wpid=315 RFC 20: ASCII format for Network Interchange File Signatures Table Comparison of Executable File Formats able_file_formats Digital Data19