Appendix. Numbering Systems. In This Appendix...

Similar documents
Appendix. Numbering Systems. In this Appendix

Number System. Introduction. Decimal Numbers

CS & IT Conversions. Magnitude 10,000 1,

Number Systems. Binary Numbers. Appendix. Decimal notation represents numbers as powers of 10, for example

UNIT 7A Data Representation: Numbers and Text. Digital Data

Digital Fundamentals

MACHINE LEVEL REPRESENTATION OF DATA

Number Systems CHAPTER Positional Number Systems

CHW 261: Logic Design

IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

What Is It? Instruction Register Address Register Data Register

Chapter 2. Data Representation in Computer Systems

CHAPTER 1 Numerical Representation

Number Systems Prof. Indranil Sen Gupta Dept. of Computer Science & Engg. Indian Institute of Technology Kharagpur Number Representation

Bits, Words, and Integers

Lecture (01) Digital Systems and Binary Numbers By: Dr. Ahmed ElShafee

Number Systems Using and Converting Between Decimal, Binary, Octal and Hexadecimal Number Systems

Final Labs and Tutors

Numbers and Representations

Number Systems. Both numbers are positive

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

DIGITAL SYSTEM DESIGN

Binary. Hexadecimal BINARY CODED DECIMAL

The type of all data used in a C++ program must be specified

Introduction to Computers and Programming. Numeric Values

COMP2611: Computer Organization. Data Representation

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

Computer Number Systems Supplement

Lecture (01) Introduction Number Systems and Conversion (1)

Memory Addressing, Binary, and Hexadecimal Review

COMP Overview of Tutorial #2

Review of Data Representation & Binary Operations Dhananjai M. Rao CSA Department Miami University

CHAPTER 3: FUNDAMENTAL OF SOFTWARE ENGINEERING FOR GAMES.

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

CS61c Midterm Review (fa06) Number representation and Floating points From your friendly reader

CS101 Lecture 04: Binary Arithmetic

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

CPE 323 REVIEW DATA TYPES AND NUMBER REPRESENTATIONS IN MODERN COMPUTERS

Chapter 2 Exercises and Answers

COMP2121: Microprocessors and Interfacing. Number Systems

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

M1 Computers and Data

Numeral Systems. -Numeral System -Positional systems -Decimal -Binary -Octal. Subjects:

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

Binary, Hexadecimal and Octal number system

Number Systems and Binary Arithmetic. Quantitative Analysis II Professor Bob Orr

CHAPTER TWO. Data Representation ( M.MORRIS MANO COMPUTER SYSTEM ARCHITECTURE THIRD EDITION ) IN THIS CHAPTER

Inf2C - Computer Systems Lecture 2 Data Representation

CS 265. Computer Architecture. Wei Lu, Ph.D., P.Eng.

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

Number Systems. The Computer Works in Binary, or how I learned to think like a computer. The computer s natural number system is binary not decimal.

Lesson #1. Computer Systems and Program Development. 1. Computer Systems and Program Development - Copyright Denis Hamelin - Ryerson University

Chapter 1 Review of Number Systems

Number representations

Objectives. Connecting with Computer Science 2

Digital Logic. The Binary System is a way of writing numbers using only the digits 0 and 1. This is the method used by the (digital) computer.

Level ISA3: Information Representation

CHAPTER 2 Data Representation in Computer Systems

Chapter 1 Preliminaries

BINARY SYSTEM. Binary system is used in digital systems because it is:

CHAPTER 2 Data Representation in Computer Systems

unused unused unused unused unused unused

Internal Data Representation

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS).

9/3/2015. Data Representation II. 2.4 Signed Integer Representation. 2.4 Signed Integer Representation

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal Representation

Signed umbers. Sign/Magnitude otation

Beyond Base 10: Non-decimal Based Number Systems

Number Systems and Number Representation

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

CMPSCI 145 MIDTERM #1 Solution Key. SPRING 2017 March 3, 2017 Professor William T. Verts

Multipliers: etc. c loo IO Digits: 2 3 ; 7 ones plus 7x l= 7 3 tens plus 3x lo= 30 2 one hundreds 2 x 100 = 200 Total 237

Computer Organisation CS303

Digital Fundamentals

Signed Binary Numbers

Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Chapter Three. Arithmetic

Programming in C++ 6. Floating point data types

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

Computer Architecture and System Software Lecture 02: Overview of Computer Systems & Start of Chapter 2

T02 Tutorial Slides for Week 2

Binary Codes. Dr. Mudathir A. Fagiri

CS 101: Computer Programming and Utilization

Representing Information. Bit Juggling. - Representing information using bits - Number representations. - Some other bits - Chapters 1 and 2.3,2.

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

CPS 104 Computer Organization and Programming Lecture-2 : Data representations,

Chapter 2: Number Systems

l l l l l l l Base 2; each digit is 0 or 1 l Each bit in place i has value 2 i l Binary representation is used in computers

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Lecture 1: Digital Systems and Number Systems

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

The type of all data used in a C (or C++) program must be specified

Python Numbers. Learning Outcomes 9/19/2012. CMSC 201 Fall 2012 Instructor: John Park Lecture Section 01 Discussion Sections 02-08, 16, 17

Computer Science 324 Computer Architecture Mount Holyoke College Fall Topic Notes: Bits and Bytes and Numbers

TOPICS. Other Number Systems. Other Number Systems 9/9/2017. Octal Hexadecimal Number conversion

Homework 1 graded and returned in class today. Solutions posted online. Request regrades by next class period. Question 10 treated as extra credit

Chapter 7. Basic Types

Transcription:

Numbering Systems ppendix In This ppendix... Introduction... inary Numbering System... exadecimal Numbering System... Octal Numbering System... inary oded ecimal () Numbering System... 5 Real (Floating Point) Numbering System... 5 /inary/ecimal/ex/octal -What is the ifference?... ata Type Mismatch... Signed vs. Unsigned Integers... 8 utomationirect.com Products and ata Types...

ppendix : Numbering Systems - Introduction s almost anyone who uses a computer is somewhat aware, the actual operations of a computer are done with a binary number system. Traditionally, the two possible states for a binary system are represented by the digits zero (0) and one (), although off and on or sometimes no and yes are closer to what is actually involved. Most of the time a typical P user has no need to think about this aspect of computers, but every now and then one gets confronted with the underlying nature of the binary system. PL user, specifically the PL programmer, should be more aware of the binary system. This appendix will provide an explanation of the numbering systems most commonly used by a PL. inary Numbering System omputers, including PLs, use the ase numbering system, which is called inary and often called ecimal. Much the same, a PL relies on only two valid digits, zero and one, or off and on respectively. You would think that it would be hard to have a numbering system built on ase with only two possible values, but the secret is by encoding using several digits. ach digit in the base system, when referenced by a computer, is called a bit. When four bits are grouped together, they form what is known as a nibble. ight bits or two nibbles would be a byte. Sixteen bits or two bytes would be a word (Table ). Thirty-two bits or two words is a double word. Word yte yte Nibble Nibble Nibble Nibble 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Table inary is not natural for us to use since we grow up using the base system. ase uses the numbers 0-. From now on, the different bases will be shown as a subscripted number following the number. xample; decimal would be. Table shows how base numbers relate to their decimal equivalents. nibble of 0 would be equal to a decimal number (* + * 0 or 8 + ). byte of would be equal to (* + * +* + * +* 0 or 8 + + + + ). inary/ecimal it Pattern it # 5 8 5 0 Power 5 8 5 0 ecimal it Value 8 8 8 0 08 L05 User Manual, th dition, Rev. 5 5 8 Max Value 555 Table 8

ppendix : Numbering Systems exadecimal Numbering System The binary numbering system can be difficult and cumbersome to interpret for some users. Therefore, the hexadecimal numbering system was developed as a convenience for humans since the PL (computer) only understands pure binary. The hexadecimal system is useful because it can represent every byte (8 bits) as two consecutive hexadecimal digits. It is easier for us to read hexadecimal numbers than binary numbers. The hexadecimal numbering system uses characters (base ) to represent values. The first ten characters are the same as our decimal system, 0-, and the first six letters of the alphabet, -F. Table lists the first eighteen decimal numbers; 0- in the left column and the equivalent hexadecimal numbers are shown in the right column. ecimal ex ecimal ex 0 0 5 5 5 F 8 8 Table Note that and in hex are not the same as and in decimal. Only the first ten numbers 0- are the same in the two representations. For example, consider the hex number 8F. To evaluate this hex number, use the same method used to write decimal numbers. ach digit in a decimal number represents a multiple of a power of ten (base ). Powers of ten increase from right to left. For example, the decimal number 5 means x + x + 5. In hex each digit represents a multiple of a power of sixteen (base ). Therefore, the hex number 8F translated to decimal means x + 8x + x + 5 = 55. owever, going through the arithmetic for hex numbers in order to evaluate them is not really necessary. The easier way is to use the calculator that comes as an accessory in Windows. It can convert between decimal and hex when in Scientific view. Note that a hex number such as 5 is not the same as the decimal number 5. Its actual value in decimal terms is x + x + 5 = 8. To avoid confusion, hex numbers are often labeled or tagged so that their meaning is clear. One method of tagging hex numbers is to append a lower case h at the end. nother method of labeling is to precede the number with 0x. Thus, the hex number 8F can also be written 8Fh. where the lower case h at the end is just a label to make sure we know that it is a hex number. lso, 8F can be written with a labeling prefix as 0x8F. L05 User Manual, th dition, Rev. -

ppendix : Numbering Systems Octal Numbering System Many of the early computers used the octal numbering system for compiled printouts. Today, the PL is about the only device that uses the Octal numbering system. The octal numbering system uses eight values to represent numbers. The values are 0- being ase 8. Table shows the first decimal digits in octal. Note that the octal values are 0-, -, 0-, and 0-. This follows the irectlogi PLs. Refer to hapter bit maps and notice that the memory addresses are numbered in octal, as well as each bit. The octal system is much like counting in the decimal system without the digits 8 and being available. The general format for four digits of the octal number is: (d x 8 0 ) + (d x 8 ) + (d x 8 ) + (d x 8 ) where d means digit. This is the same format used in the binary, decimal, or hexadecimal systems except that the base number for octal is 8. Using the powers of expansion, the example below shows octal 0 converted to decimal. positional value Octal ecimal Octal ecimal 0 0 0 8 0 5 5 5 8 0 5 8 5 5 0 5 5 8 0 Table 0 x 8 0 = 0 x = 0 x 8 = x 8 = x 8 = x = 8 x 8 = x 5 = 08 50 decimal equivalent - L05 User Manual, th dition, Rev.

ppendix : Numbering Systems inary oded ecimal () Numbering System is a numbering system where four bits are used to represent each decimal digit. The binary codes corresponding to the hexadecimal digits -F are not used in the system. For this reason numbers cannot be coded as efficiently using the system. For example, a byte can represent a maximum of 5 different numbers (i.e., 0-55) using normal binary, whereas only 0 distinct numbers (i.e., 0-) could be coded using. lso, note that is a subset of hexadecimal and neither one does negative numbers. it Pattern it # 5 8 5 0 Power 0 it Value 8 8 8 8 Max Value Table 5 One plus for is that it reads like a decimal number, whereas 8 in would mean 8 decimal. No conversion is needed; however, within the PL, calculations can be performed if numbers are adjusted to after normal binary arithmetic. Real (Floating Point) Numbering System The terms Real and floating-point both describe I-5 floating point arithmetic. This standard specifies how single precision (-bit) and double precision (-bit) floating point numbers are to be represented as well as how arithmetic should be carried out on them. Most PLs use the -bit format for floating point (or Real) numbers which will be discussed here. Real (Floating Point ) it Pattern it # 0 8 5 0 8 Sign xponent Mantissa it # 5 8 5 0 Mantissa (continues from above) Table Floating point numbers which irectlogi PLs use have three basic components: sign, exponent and mantissa. The -bit word required for the I standard floating point numbers is shown in Table. It is represented as a number from 0 to, left to right. The first bit () is the sign bit, the next eight bits (0-) are the exponent bits and the final bits (-0) are the fraction bits. In summary: The sign bit is either 0 for positive or for negative; The exponent uses base ; The first bit of the mantissa is typically assumed to be.fff, where f is the field of fraction bits. The Internet can provide a more in-depth explanation of the floating point numbering system. One website to look at is: http://www.psc.edu/general/software/packages/ieee/ieee.html L05 User Manual, th dition, Rev. -5

ppendix : Numbering Systems /inary/ecimal/ex/octal - What is the ifference? Sometimes there is confusion about the differences between the data types used in a PL. The PL s native data format is, while the I/O numbering system is octal. Other numbering formats used are binary and Real. lthough data is stored in the same manner (0s and s), there are differences in the way that the PL interprets it. While all of the formats rely on the base numbering system and bit-coded data, the format of the data is dissimilar. Table below shows the bit patterns and values for various formats. inary/ecimal it Pattern it # 5 8 5 0 ecimal it Value 8 8 8 0 08 5 Max Value 555 exadecimal it Pattern it # 5 8 5 0 ecimal it Value 8 8 8 8 Max Value F F F F it Pattern it # 5 8 5 0 ecimal it Value 8 8 8 8 Max Value Octal it Pattern it # 5 8 5 0 it Value Max Value Real (Floating Point ) Pattern it # 0 8 5 0 8 Sign xponent Mantissa it # 5 8 5 0 Mantissa (continued from above) 5 Table s seen in Table, the and hexadecimal formats are similar, although the maximum number for each grouping is different ( for and F for hexadecimal). This allows both formats to use the same display method. The unfortunate side effect is that unless the data type is documented, it s difficult to know what the data type is unless it contains the letters -F. 8 8 - L05 User Manual, th dition, Rev.

ppendix : Numbering Systems ata Type Mismatch ata type mismatching is a common problem when using an operator interface. iagnosing it can be a challenge until you identify the symptoms. Since the PL uses as the native format, many people tend to think it is interchangeable with binary (unsigned integer) format. This is true to some extent, but not in this case. Table 8 shows how and binary numbers differ. ata Type Mismatch ecimal 0 5 8 0000 000 00 00 00 0 0 0 00 0 000 0000 000 000 inary 0000 000 00 00 00 0 0 0 00 0 0000 0000 Table 8 s the table shows, and binary share the same bit pattern up until you get to the decimal number. Once you get past, the bit pattern changes. The bit pattern for the decimal is actually equal to a value of in binary, causing the number to jump six digits when viewing it as. With larger numbers, the error multiplies. inary values from to 5 ecimal are actually invalid for the data type. Looking at a larger number, such as the value shown in Table, both the bit pattern and the decimal bit pattern correspond to a base value of 05. If bit patterns are read, or interpreted, in a different format than what is used to write them, the data will not be correct. For instance, if the bit pattern is interpreted as a decimal (binary) bit pattern, the result is a base value of 5. Similarly, if you try to view the decimal (binary) bit pattern as a value, it is not a valid value at all, but could be represented in hexadecimal as 0xFFF. Look at the following example and note the same value represented by the different numbering systems. ase Value it Pattern inary it Pattern 05 00 0000 0 0 00 00 inary ecimal ex 0 0 0 Octal Table 000 00 00 00 inary 0 ecimal ex 00 0 0 0000 0 Octal L05 User Manual, th dition, Rev. -

ppendix : Numbering Systems Signed vs. Unsigned Integers So far, we have dealt with unsigned data types only. Now we will deal with signed data types (negative numbers). The and hexadecimal numbering systems do not use signed data types. In order to signify that a number is negative or positive, we must assign a bit to it. Usually, this is the Most Significant it (MS) as shown in Table. For a -bit number, this is bit 5. This means that for -bit numbers we have a range of - to. it # 5 8 5 0 MS Table There are two ways to encode a negative number: two s complement and Magnitude Plus sign. The two methods are not compatible. The simplest method to represent a negative number is to use one bit of the PL word as the sign of a number while the remainder of the word gives its magnitude. It is general convention to use the most significant bit (MS) as the sign bit: a will indicate a negative, and a 0 will indicate a positive number. Thus, a -bit word allows numbers in the range ±. Table shows a representation of 0 and a representation of -0 in this format. Magnitude Plus Sign ecimal inary 0 0000 0000 0 00-0 00 0000 0 00 Table Two s complement is a bit more complicated. simple formula for two s complement is to invert the binary and add one (see Table ). asically, s are being changed to 0s and all 0s are being changed to. Two s omplement ecimal inary 0 0000 0000 0 00-0 0 Table More information about s complement can be found on the Internet at the following website: https://www.cs.cornell.edu/~tomf/notes/cps/twoscomp.html#fromtwo LS -8 L05 User Manual, th dition, Rev.

ppendix : Numbering Systems utomationirect.com Products and ata Types irectlogi PLs The irectlogi PL family uses the octal numbering system for all addressing which includes: inputs, outputs, internal V-memory locations, timers, counters, internal control relays (bits), etc. Most data in the PL, including timer and counter current values, is in format by default. User data in V-memory locations may be stored in other data types if it is changed by the programmer, or comes from some external source, such as an operator interface. ny manipulation of data must use instructions appropriate for that data type which includes: Load instructions, Math instructions, Out box instructions, comparison instructions, etc. In many cases, the data can be changed from one data type to another, but be aware of the limitations of the various data types when doing so. For example, to change a value from to decimal (binary), use a IN instruction box. To change from to a real number, use a IN and a TOR instruction box. When using Math instructions, the data types must match. For example, a or decimal (binary) number cannot be added to a real number, and a number cannot be added to a decimal (binary) number. If the data types are mismatched, the results of any math operation will be meaningless. To simplify number conversions, Intelligent ox (Iox) Instructions are available with irectsoft. These instruction descriptions are located in Volume, page 5-0, in the Math Iox group. Most irectlogi analog modules can be set up to give the raw data in decimal (binary) format or in format, so it is necessary to know how the module is being used. irectlogi PI is another area where not all values are in. In fact, nearly all of the PI parameters are stored in the PL memory as decimal (binary) numbers. NOT: The PI algorithm uses magnitude plus sign for negative decimal (binary) numbers, whereas the standard math functions use two s complement. This can cause confusion while debugging a PI loop. When using the ata View in irectsoft, be certain that the proper format is selected for the element to be viewed. The data type and length are selected using the drop-down boxes at the top of the ata View window. lso notice that is called /ex. Remember that is a subset of hexadecimal so they share a display format even though the values may be different. This is where good documentation of the data type stored in memory is crucial. -more/-more Micro-Graphic Panels In the -more and -more Micro-Graphic MI operator panels, the -bit format is listed as int. inary format is either Unsigned int or Signed int depending on whether or not the value can be negative. Real number format is Floating PT. More available formats are, int, Unsigned int and Signed int. L05 User Manual, th dition, Rev. -

ppendix : Numbering Systems Notes - L05 User Manual, th dition, Rev.