1 Number Representation CS10001: Programming & Data Structures Pallab Dasgupta Professor, Dept. of Computer Sc. & Engg., Indian Institute of Technology Kharagpur
2 Topics to be Discussed How are numeric data items actually stored in computer memory? How much space (memory locations) is allocated for each type of data? int, float, char, etc. How are characters and strings stored in memory?
3 Number System :: The Basics We are accustomed to using the so-called decimal number system. Ten digits :: 0,1,2,3,4,5,6,7,8,9 Every digit position has a weight which is a power of 10. Base or radix is 10. Example: 234 = 2 x x x = 2 x x x x x 10-2
4 Binary Number System Two digits: 0 and 1. Every digit position has a weight which is a power of 2. Base or radix is 2. Example: 110 = 1 x x x = 1 x x x x x 2-2
5 Binary-to-Decimal Conversion Each digit position of a binary number has a weight. Some power of 2. A binary number: B = b n-1 b n-2..b 1 b 0. b -1-1 b b -m Corresponding value in decimal: n-1 D = Σ i = -m b i 2 i
6 Examples x x x x x x2 0 = 43 (101011) 2 = (43) x2 + 1x2 + 0x2 + 1x2 =.3125 (.0101) 2 = (.3125) x x x x2 + 1x (101.11) 2 = (5.75) 10
7 Decimal-to-Binary Conversion Consider the integer and fractional parts separately. For the integer part, Repeatedly divide the given number by 2, and go on accumulating the remainders, until the number becomes zero. Arrange the remainders in reverse order. For the fractional part, Repeatedly multiply the given fraction by 2. Accumulate the integer part (0 or 1). If the integer part is 1, chop it off. Arrange the integer parts in the order they are obtained.
8 Example 1 :: (239) 10 = ( ) 2
9 Example 2 :: (64) 10 = ( ) 2
10 Example 3 :: x 2 = x 2 = x 2 = x 2 = x 2 = : : (.634) 10 = ( ) 2
12 Hexadecimal Number System A compact way of representing binary numbers. 16 different symbols (radix = 16) A B C D E F 1111
13 Binary-to-Hexadecimal Conversion For the integer part, Scan the binary number from Scan the binary number from right to left. Translate each group of four bits into the corresponding hexadecimal digit. Add leading zeros if necessary. For the fractional part, Scan the binary number from Scan the binary number from left to right. Translate each group of four bits into the corresponding hexadecimal digit. Add trailing zeros if necessary.
16 Unsigned Binary Numbers An n-bit binary number B = b n-1 b n-2. b 2 b 1 b 0 2 n distinct combinations are possible, 0 to 2 n -1. For example, for n = 3, there are 8 distinct combinations. 000, 001, 010, 011, 100, 101, 110, 111 Range of numbers that can be represented n=8 0 to (255) n=16 0 to 2-1 (65535) n=32 0 to 2-1 ( )
17 Signed Integer Representation Many of the numerical data items that are used in a program are signed (positive or negative). Question:: How to represent sign? Three possible approaches: Sign-magnitude representation One s complement representation Two s complement representation
18 Sign-magnitude Representation For an n-bit number representation The most significant bit (MSB) indicates sign 0 positive 1 negative The remaining n-1 bits represent magnitude. b n-1 b n-2 b 1 b 0 Sign Magnitude
19 Contd. Range of numbers that can be represented: Maximum :: + (2 n-1 1) Minimum :: (2 n-1 1) A problem: Two different representations of zero
20 One s Complement Representation Basic idea: Positive numbers are represented exactly as in sign- magnitude form. Negative numbers are represented in 1 s complement form. How to compute the 1 s complement of a number? Complement every bit of the number (1 0 and 0 0 1). MSB will indicate the sign of the number. 0 positive 1 negative
21 Example :: n= To find the representation of, say, -4, first note that +4 = = 1 s complement of 0100 = 1011
22 Contd. Range of numbers that can be represented: Maximum :: + (2 n-1 1) Minimum :: (2 n-1 1) A problem: Two different representations of zero Advantage of 1 s complement representation Subtraction can be done using addition. Leads to substantial saving in circuitry.
23 Two s Complement Representation Basic idea: Positive numbers are represented exactly as in sign- magnitude form. Negative numbers are represented in 2 s complement form. How to compute the 2 s complement of a number? Complement every bit of the number (1 0 and 0 0 1), and then add one to the resulting number. MSB will indicate the sign of the number. 0 positive 1 negative
24 Example :: n= To find the representation of, say, -4, first note that +4 = = 2 s complement of 0100 = = 1100
25 Contd. Range of numbers that can be represented: Maximum :: + (2 n-1 1) Minimum :: 2 n-1 Advantage: Unique representation of zero. Subtraction can be done using addition. Leads to substantial saving in circuitry. Almost all computers today use the 2 s complement representation for storing negative numbers.
26 Contd. In C short int 16 bits + (2 15-1) to int 32 bits + (2 31-1) to long int 64 bits + (2 63-1) to -2 63
27 Subtraction Using Addition :: 1 s Complement How to compute A B? Compute the 1 s complement of B (say, B 1 ). Compute R = A + B 1 If the carry obtained after addition is 1 Add the carry back to R (called end-around carry). That is, R = R + 1. The result is a positive number. Else The result is negative, and is in 1 s complement form.
28 Example 1 :: s complement of 2 = :: :: A B 1 R Assume 4-bit representations. Since there is a carry, it is added back to the result. End-around carry The result is positive.
29 Example 2 :: s complement of 5 = :: :: A B 1 R Assume 4-bit representations. -2 Since there is no carry, the result is negative is the 1 s complement of 0010, that is, it represents 2.
30 Subtraction Using Addition :: 2 s Complement How to compute A B? Compute the 2 s complement of B (say, B 2 ). Compute R = A + B 2 If the carry obtained after addition is 1 Ignore the carry. The result is a positive number. Else The result is negative, and is in 2 s complement form.
31 Example 1 :: s complement of 2 = = :: 0110 A -2 :: B 2 Assume 4-bit representations. Ignore carry +4 R Presence of carry indicates that the result is positive. No need to add the endaround carry like in 1 s complement.
32 Example 2 :: s complement of 5 = = :: :: A B 2 R Assume 4-bit representations. -2 Since there is no carry, the result is negative is the 2 s complement of 0010, that is, it represents 2.
33 Floating-point Numbers The representations discussed so far applies only to integers. Cannot represent numbers with fractional parts. We can assume a decimal point before a 2 s complement number. In that case, pure fractions (without integer parts) can be represented. We can also assume the decimal point somewhere in between. This lacks flexibility. Very large and very small numbers cannot be represented.
34 Representation of Floating-Point Numbers A floating-point number F is represented by a doublet <M,E> : F = M x B E B exponent base (usually 2) M mantissa E exponent M is usually represented in 2 s complement form, with an implied decimal point before it. For example, In decimal, x 10 6 In binary, x
35 Example :: 32-bit representation M E M represents a 2 s complement fraction 1 > M > -1 E represents the exponent (in 2 s complement form) 127 > E > -128 Points to note: 24 8 The number of significant digits depends on the number of bits in M. 6 significant digits for 24-bit mantissa. The range of the number depends on the number of bits in E to for 8-bit exponent.
36 A Warning The representation for floating-point numbers as shown is just for illustration. The actual representation is a little more complex. In C: float :: 32-bit representation double :: 64-bit representation
37 Representation of Characters Many applications have to deal with non-numerical data. Characters and strings. There must be a standard mechanism to represent alphanumeric and other characters in memory. Three standards in use: Extended Binary Coded Decimal Interchange Code (EBCDIC) Used in older IBM machines. American Standard Code for Information Interchange (ASCII) Most widely used today. UNICODE Used to represent all international characters. Used by Java.
38 ASCII Code Each individual character is numerically encoded into a unique 7- bit binary code. A total of 2 7 or 128 different characters. A character is normally encoded in a byte (8 bits), with the MSB not been used. The binary encoding of the characters follow a regular ordering. Digits are ordered consecutively in their proper numerical sequence (0 to 9). Letters (uppercase and lowercase) are arranged consecutively in their proper alphabetic order.
40 Character Strings Two ways of representing a sequence of characters in memory. The first location contains the number of characters in the string, followed by the actual characters. 5 H e l l o The characters follow one another, and is terminated by a special delimiter. H e l l o
41 String Representation in C In C, the second approach is used. The \0 character is used as the string delimiter. Example: Hello H e l l o \0 A null string occupies one byte in memory. Only the \0 character.
ECE Department Summer LECTURE #5: Number Systems EEL : Digital Logic and Computer Systems Based on lecture notes by Dr. Eric M. Schwartz Decimal Number System: -Our standard number system is base, also
LSN 2 Number Systems Department of Engineering Technology LSN 2 Decimal Number System Decimal number system has 10 digits (0-9) Base 10 weighting system... 10 5 10 4 10 3 10 2 10 1 10 0. 10-1 10-2 10-3
Slide 1/30 Learning Objectives In this chapter you will learn about: Computer data Computer codes: representation of data in binary Most commonly used computer codes Collating sequence 36 Slide 2/30 Data
Digital System Design Prof. D Roychoudhry Department of Computer Science and Engineering Indian Institute of Technology, Kharagpur Lecture - 04 Digital Logic II May, I before starting the today s lecture
CDA 3200 Digital Systems Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012 Outline Data Representation Binary Codes Why 6-3-1-1 and Excess-3? Data Representation (1/2) Each numbering
CSI 333 Lecture 1 Number Systems 1 1 / 23 Basics of Number Systems Ref: Appendix C of Deitel & Deitel. Weighted Positional Notation: 192 = 2 10 0 + 9 10 1 + 1 10 2 General: Digit sequence : d n 1 d n 2...
2/9/9 Binary number system Computer (electronic) systems prefer binary numbers Binary number: represent a number in base-2 Binary numbers 2 3 + 7 + 5 Some terminology Bit: a binary digit ( or ) Hexadecimal
Unit- I Introduction to c Language: C is a general-purpose computer programming language developed between 1969 and 1973 by Dennis Ritchie at the Bell Telephone Laboratories for use with the Unix operating
G InThisAppendix... Introduction Binary Numbering System Hexadecimal Numbering System Octal Numbering System Binary Coded Decimal (BCD) Numbering System Real (Floating Point) Numbering System BCD/Binary/Decimal/Hex/Octal
Computer Science 281 Binary and Hexadecimal Review 1 The Binary Number System Computers store everything, both instructions and data, by using many, many transistors, each of which can be in one of two
NUMBER SYSTEMS 1.1 Introduction There are several number systems which we normally use, such as decimal, binary, octal, hexadecimal, etc. Amongst them we are most familiar with the decimal number system.
Binary Representation The basis of all digital data is binary representation. Binary - means two 1, 0 True, False Hot, Cold On, Off We must be able to handle more than just values for real world problems
EE 261 Introduction to Logic Circuits Module #2 Number Systems Topics A. Number System Formation B. Base Conversions C. Binary Arithmetic D. Signed Numbers E. Signed Arithmetic F. Binary Codes Textbook
Chapter 3 3.1 Decimal System The radix or base of a number system determines the total number of different symbols or digits used by that system. The decimal system has a base of 10 with the digits 0 through
Binary Numbers In computer science we deal almost exclusively with binary numbers. it will be very helpful to memorize some binary constants and their decimal and English equivalents. By English equivalents
Lecture 2 Binary and Hexadecimal Numbers Purpose: Review binary and hexadecimal number representations Convert directly from one base to another base Review addition and subtraction in binary representations
Chapter 3 Data Storage Objectives After studying this chapter, students should be able to: List five different data types used in a computer. Describe how integers are stored in a computer. Describe how
Lecture 11: Number Systems Numeric Data Fixed point Integers (12, 345, 20567 etc) Real fractions (23.45, 23., 0.145 etc.) Floating point such as 23. 45 e 12 Basically an exponent representation Any number
NUMBER SYSTEMS William Stallings The Decimal System... The Binary System...3 Converting between Binary and Decimal...3 Integers...4 Fractions...5 Hexadecimal Notation...6 This document available at WilliamStallings.com/StudentSupport.html
Exercises 1 - number representations Questions 1. Give the 16 bit signed (twos complement) representation of the following decimal numbers, and convert to hexadecimal: (a) 3012 (b) - 435 2. For each of
CPEN 4 - Digital Logic Design Binary Systems C. Gerousis Digital Design 3 rd Ed., Mano Prentice Hall Digital vs. Analog An analog system has continuous range of values A mercury thermometer Vinyl records
Numeral Systems Which number is larger? 25 8 We need to distinguish between numbers and the symbols that represent them, called numerals. The number 25 is larger than 8, but the numeral 8 above is larger
Base Conversion written by Cathy Saxton 1. Base 10 In base 10, the digits, from right to left, specify the 1 s, 10 s, 100 s, 1000 s, etc. These are powers of 10 (10 x ): 10 0 = 1, 10 1 = 10, 10 2 = 100,
3 Data Storage 3.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List five different data types used in a computer. Describe how
HOMEWORK # 2 SOLUTIO Problem 1 (2 points) a. There are 313 characters in the Tamil language. If every character is to be encoded into a unique bit pattern, what is the minimum number of bits required to
Number Bases //9 Goals Numbers Understand binary and hexadecimal numbers Be able to convert between number bases Understand binary fractions COMP37 Introduction to Computer Architecture Unary Numbers Decimal
CS101 Lecture 11: Number Systems and Binary Numbers Aaron Stevens 14 February 2011 1 2 1 3!!! MATH WARNING!!! TODAY S LECTURE CONTAINS TRACE AMOUNTS OF ARITHMETIC AND ALGEBRA PLEASE BE ADVISED THAT CALCULTORS
Binary Representation The basis of all digital data is binary representation. Binary - means two 1, 0 True, False Hot, Cold On, Off We must tbe able to handle more than just values for real world problems
Divide: Paper & Pencil Computer Architecture ALU Design : Division and Floating Point 1001 Quotient Divisor 1000 1001010 Dividend 1000 10 101 1010 1000 10 (or Modulo result) See how big a number can be
23CH_PHCalter_TMSETE_949118 23/2/2007 1:37 PM Page 1 Binary, Hexadecimal, Octal, and BCD Numbers OBJECTIVES When you have completed this chapter, you should be able to: Convert between binary and decimal
The programming language C sws1 1 The programming language C invented by Dennis Ritchie in early 1970s who used it to write the first Hello World program C was used to write UNIX Standardised as K&C (Kernighan
The New IoT Standard: Any App for Any Device Using Any Data Format Mike Weiner Product Manager, Omega DevCloud KORE Telematics About KORE The world s largest M2M/IoT services provider 12 Carriers Enterprise
Chapter 2 Encoding Text with a Small Alphabet Given the nature of the Internet, we can break the process of understanding how information is transmitted into two components. First, we have to figure out
Binary numbers The reason humans represent numbers using decimal (the ten digits from 0,1,... 9) is that we have ten fingers. There is no other reason than that. There is nothing special otherwise about
Binary Numbering Systems April 1997, ver. 1 Application Note 83 Introduction Binary numbering systems are used in virtually all digital systems, including digital signal processing (DSP), networking, and
Introduction to Embedded Microcomputer Systems Lecture 5.1 2.9. Conversions ASCII to binary n = 100*(Data-0x30) + 10*(Data-0x30) + (Data-0x30); This 3-digit ASCII string could also be calculated
Digital Design Assoc. Prof. Dr. Berna Örs Yalçın Istanbul Technical University Faculty of Electrical and Electronics Engineering Office Number: 2318 E-mail: firstname.lastname@example.org Grading 1st Midterm -
ECE 0142 Computer Organization Lecture 3 Floating Point Representations 1 Floating-point arithmetic We often incur floating-point programming. Floating point greatly simplifies working with large (e.g.,
ASCII Code Data coding Morse code was the first code used for long-distance communication. Samuel F.B. Morse invented it in 1844. This code is made up of dots and dashes (a sort of binary code). It was
Cyber Security Workshop Encryption Reference Manual May 2015 Basic Concepts in Encoding and Encryption Binary Encoding Examples Encryption Cipher Examples 1 P a g e Encoding Concepts Binary Encoding Basics
This sub chapter discusses another architecture, that of the JVM (Java Virtual Machine). In general, a VM (Virtual Machine) is a hypothetical machine (implemented in either hardware or software) that directly
INTERNATIONAL STANDARD ISO/IEC 9899:1999 TECHNICAL CORRIGENDUM 2 Published 2004-11-15 INTERNATIONAL ORGANIZATION FOR STANDARDIZATION МЕЖДУНАРОДНАЯ ОРГАНИЗАЦИЯ ПО СТАНДАРТИЗАЦИИ ORGANISATION INTERNATIONALE
Section.4 Place Value Systems of Numeration in Other Bases Other Bases The Hindu-Arabic system that is used in most of the world today is a positional value system with a base of ten. The simplest reason
Digital Logic Design Introduction A digital computer stores data in terms of digits (numbers) and proceeds in discrete steps from one state to the next. The states of a digital computer typically involve
Chapter 1. Binary, octal and hexadecimal numbers This material is covered in the books: Nelson Magor Cooke et al, Basic mathematics for electronics (7th edition), Glencoe, Lake Forest, Ill., 1992. [Hamilton
DNA Data and Program Representation Alexandre David 1.2.05 email@example.com Introduction Very important to understand how data is represented. operations limits precision Digital logic built on 2-valued
Binary Numbers Binary Octal Hexadecimal Binary Numbers COUNTING SYSTEMS UNLIMITED... Since you have been using the 10 different digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 all your life, you may wonder how
Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class: L&L, 2.1-2.3, App C 1 Primitive Data There are eight
CS3 Introduction to Numerical Methods Lecture Number Representations and Errors Professor Jun Zhang Department of Computer Science University of Kentucky Lexington, KY 40506-0633 August 7, 05 Number in
Chapter 3. DATA_TYPE Values and Data File Storage Formats 3-1 Chapter 3. DATA_TYPE Values and Data File Storage Formats Each PDS archived product is described using label objects that provide information
Modbus Frequently Asked Questions WP-34-REV0-0609-1/7 The Answer to the 14 Most Frequently Asked Modbus Questions Exactly what is Modbus? Modbus is an open serial communications protocol widely used in
Page 1 of 5 Unsigned Conversions from Decimal or to Decimal and other Number Systems In all digital design, analysis, troubleshooting, and repair you will be working with binary numbers (or base 2). It
APPENDIX B Positional Numbering System A positional numbering system uses a set of symbols. The value that each symbol represents, however, depends on its face value and its place value, the value associated
Today s topics! Binary Numbers! Brookshear.-.! Slides from Prof. Marti Hearst of UC Berkeley SIMS! Upcoming! Networks Interactive Introduction to Graph Theory http://www.utm.edu/cgi-bin/caldwell/tutor/departments/math/graph/intro
ERRORS and COMPUTER ARITHMETIC Types of Error in Numerical Calculations Initial Data Errors: from experiment, modeling, computer representation; problem dependent but need to know at beginning of calculation.
146 CHAPTER 3 Information Representation The sign bit is 1, so the number is negative. Converting to decimal gives 37A (hex) = 134 (dec) Notice that the hexadecimal number is not written with a negative
CSC45 AUTOMATA 2. Finite Automata: Examples and Definitions Finite Automata: Examples and Definitions A finite automaton is a simple type of computer. Itsoutputislimitedto yes to or no. It has very primitive
Decimal Division Remember 4th grade long division? 43 // quotient 12 521 // divisor dividend -480 41-36 5 // remainder Shift divisor left (multiply by 10) until MSB lines up with dividend s Repeat until
Application Note 154 LabVIEW Data Storage Introduction This Application Note describes the formats in which you can save data. This information is most useful to advanced users, such as those using shared
Number Systems Introduction / Number Systems Data Representation Data representation can be Digital or Analog In Analog representation values are represented over a continuous range In Digital representation
NUMBER SYSTEMS TUTORIAL Courtesy of: thevbprogrammer.com Number Systems Concepts The study of number systems is useful to the student of computing due to the fact that number systems other than the familiar
Chapter 1: Digital Systems and Binary Numbers Digital age and information age Digital computers general purposes many scientific, industrial and commercial applications Digital systems telephone switching
C5 Solutions 1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12 To Compute 0 0 = 00000000 To Compute 1 Step 1. Convert 1 to binary 00000001 Step 2. Flip the bits 11111110
CHAPTER 2 MACHINE INSTRUCTIONS AND PROGRAMS CHAPTER OBJECTIVES In this chapter you will learn about: Machine instructions and program execution, including branching and subroutine call and return operations
Chapter 1 1. Introductory Overview The main goal of this chapter is to review fundamental aspects of analogue and digital signals and systems, digital codes, the binary, decimal and hexadecimal numbering
Stacks Linear data structures Collection of components that can be arranged as a straight line Data structure grows or shrinks as we add or remove objects ADTs provide an abstract layer for various operations
The use of binary codes to represent characters Teacher s Notes Lesson Plan x Length 60 mins Specification Link 2.1.4/hi Character Learning objective (a) Explain the use of binary codes to represent characters
Counting in base 10, 2 and 16 1. Binary Numbers A super-important fact: (Nearly all) Computers store all information in the form of binary numbers. Numbers, characters, images, music files --- all of these
This Unit: Floating Point Arithmetic CIS 371 Computer Organization and Design Unit 7: Floating Point App App App System software Mem CPU I/O Formats Precision and range IEEE 754 standard Operations Addition
Correctly Rounded Floating-point Binary-to-Decimal and Decimal-to-Binary Conversion Routines in Standard ML By Prashanth Tilleti Advisor Dr. Matthew Fluet Department of Computer Science B. Thomas Golisano
Data Storage: Computers are made of many small parts, including transistors, capacitors, resistors, magnetic materials, etc. Somehow they have to store information in these materials both temporarily (RAM,
Intel Hexadecimal Object File Format Specification Revision A, 1/6/88 DISCLAIMER Intel makes no representation or warranties with respect to the contents hereof and specifically disclaims any implied warranties
Chapter 5. Binary, octal and hexadecimal numbers A place to look for some of this material is the Wikipedia page http://en.wikipedia.org/wiki/binary_numeral_system#counting_in_binary Another place that
CHAPTER 5 5.1. Introduction Obfuscation is a process of converting original data into unintelligible data. It is similar to encryption but it uses mathematical calculations or programming logics. Encryption
Memory Structure Memory is implemented as an array of electronic switches Each switch can be in one of two states 0 or 1, on or off, true or false, purple or gold, sitting or standing BInary digits (bits)