Appendix. Numbering Systems. In this Appendix

Similar documents
Appendix. Numbering Systems. In This Appendix...

Number System. Introduction. Decimal Numbers

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

CS & IT Conversions. Magnitude 10,000 1,

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 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

Chapter 2. Data Representation in Computer Systems

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

COMP Overview of Tutorial #2

Memory Addressing, Binary, and Hexadecimal Review

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

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

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

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

COMP2121: Microprocessors and Interfacing. Number Systems

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

CHAPTER 3: FUNDAMENTAL OF SOFTWARE ENGINEERING FOR GAMES.

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

Inf2C - Computer Systems Lecture 2 Data Representation

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

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)

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

CS101 Lecture 04: Binary Arithmetic

Objectives. Connecting with Computer Science 2

Level ISA3: Information Representation

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.

M1 Computers and Data

Chapter 1 Preliminaries

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

CHAPTER 2 Data Representation in Computer Systems

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

Chapter 2 Exercises and Answers

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.

Course Schedule. CS 221 Computer Architecture. Week 3: Plan. I. Hexadecimals and Character Representations. Hexadecimal 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

Signed umbers. Sign/Magnitude otation

Number Systems and Number Representation

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

Beyond Base 10: Non-decimal Based Number Systems

Computer Organisation CS303

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

Digital Fundamentals

Signed Binary Numbers

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

Chapter Three. Arithmetic

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

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.

Binary Codes. Dr. Mudathir A. Fagiri

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,

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

Chapter 2: Number Systems

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

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

Lecture 1: Digital Systems and Number Systems

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

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

Excerpt from: Stephen H. Unger, The Essence of Logic Circuits, Second Ed., Wiley, 1997

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

Digital Computers and Machine Representation of Data

Transcription:

Numbering Systems ppendix n this ppendix ntroduction... 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 ntegers... 8 utomationirect.com Products and ata Types... 9

ppendix : Numbering Systems 0 ntroduction 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 for 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 should be more aware of the binary system specifically the PL programmer. 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. Like in a computer there are only two valid digits a PL relies on, 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 0 system. ase 0 uses the numbers 0-9, as we are all well aware. From now on, the different bases will be shown as a subscripted number following the number. xample; 0 decimal would be 0 0. Table shows how base numbers relate to their decimal equivalents. nibble of 00 would be equal to a decimal number 9 (* + * 0 or 8 0 + 0 ). byte of 000 would be equal to (* + * +* + * +* 0 or 8 0 + 0 + 0 + 0 + 0 ). inary/ecimal it Pattern it # 5 0 9 8 5 0 Power 5 0 9 8 5 0 ecimal it Value 8 8 89 09 08 0 5 5 8 Max Value 555 0 Table 8 - L05 Micro PL User Manual, th dition, Rev.

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. t 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-9, 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 9 9 0 5 5 5 F 0 8 8 Table Note that 0 and in hex are not the same as 0 and in decimal. Only the first ten numbers 0-9 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 0). Powers of ten increase from right to left. For example, the decimal number 5 means x0 + x0 + 5. n hex each digit represents a multiple of a power of sixteen (base ). Therefore, the hex number 8F translated to decimal means x + 8x + 0x + 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. t 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. ts actual value in decimal terms is x x + 5 = 89. 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. 0 L05 Micro PL User Manual, th dition, Rev. -

ppendix : Numbering Systems 0 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 8 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-, 0-, and 0-. This follows the irectlog 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 9 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 9 0 5 5 5 0 8 0 9 5 0 8 5 5 9 0 5 Table 5 8 0 0 x 8 0 = 0 x = 0 x 8 = x 8 = x 8 = x = 8 x 8 = x 5 = 08 50 decimal equivalent - L05 Micro PL 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 00 distinct numbers (i.e. 0-99) could be coded using. lso, note that is a subset of hexadecimal and neither one does negative numbers. it Pattern it # 5 0 9 8 5 0 Power 0 0 0 0 0 it Value 8 8 8 8 Max Value 9 9 9 9 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 -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 Real (Floating Point ) it Pattern it # 0 9 8 5 0 9 8 Sign xponent Mantissa it # 5 0 9 8 5 0 Mantissa (continues from above) Table PLs use the -bit format for floating point (or Real) numbers which will be discussed here. Floating point numbers which irectlog PLs use have three basic components: sign, exponent and mantissa. The bit word required for the standard floating point numbers is shown in Table. t 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. n 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. 0 L05 Micro PL User Manual, th dition, Rev. -5

0 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 /O numbering system is octal. Other numbering formats used are binary and Real. lthough data is stored in the same manner (0 s 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 0 9 8 5 0 ecimal it Value 8 8 89 09 08 0 0 5 5 s seen in Table, the and hexadecimal formats are similar, although the maximum number for each grouping is different (9 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. 5 Max Value 555 8 exadecimal it Pattern it # 5 0 9 8 5 0 ecimal it Value 8 8 8 8 Max Value F F F F it Pattern it # 5 0 9 8 5 0 ecimal it Value 8 8 8 8 Max Value 9 9 9 9 Octal it Pattern it # 5 0 9 8 5 0 it Value Max Value Real (Floating Point ) it Pattern it # 0 9 8 5 0 9 8 Sign xponent Mantissa it # 5 0 9 8 5 0 5 Mantissa (continued from above) Table 8 8 8 - L05 Micro PL 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 9 0 0000 000 000 00 000 00 00 0 000 00 000 0000 000 000 inary 0000 000 000 00 000 00 00 0 000 00 0000 00 0000 0 s the table shows, and binary share the same bit pattern up until you get to the decimal number 0. Once you get past 0, the bit pattern changes. The bit pattern for the decimal 0 is actually equal to a value of in binary, causing the number to jump six digits by when viewing it as the. With larger numbers, the error multiplies. inary values from 0 to 5 ecimal are actually invalid for the data type. Looking at a larger number, such as the value shown in Table 9, both the bit pattern and the decimal bit pattern correspond to a base 0 value of 095 0. f 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 0 value of 5 0. 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. ase 0 Value it Pattern inary it Pattern 095 000 0000 00 00 Table 9 Table 8 Look at the following example and note the same value represented by the different numbering systems. 000 00 inary ecimal ex 00 0 0 Octal 000 000 00 000 inary 0 ecimal ex 000 00 00 0000 0 Octal 0 L05 Micro PL User Manual, th dition, Rev. -

ppendix : Numbering Systems 0 Signed vs. Unsigned ntegers 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. n 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 0. For a -bit number, this is bit 5. This means that for -bit numbers we have a range of - to. it # 5 0 9 8 5 0 MS Table 0 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. t is general convention to use the most significant bit (MS) as the sign bit: a will indicate a negative, and a 0 a positive number. Thus, a bit word allows numbers in the range ±. Table shows a representations of 00 and a representation of -00 in this format. Magnitude Plus Sign ecimal inary 00 0000 0000 00 000-00 000 0000 00 000 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 0 s and all 0 s are being changed to. Two s omplement ecimal inary 00 0000 0000 00 000-00 00 00 Table LS -8 L05 Micro PL User Manual, th dition, Rev.

ppendix : Numbering Systems utomationirect.com Products and ata Types irectlog PLs The irectlog 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. n 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 N instruction box. To change from to a real number, use a N 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. f the data types are mismatched, the results of any math operation will be meaningless. To simplify making, number conversions ntelligent ox (ox) nstructions are available with irectsoft 5. These instruction descriptions are located in Volume, hapter 5, in the Math ox group. Most irectlog analog modules can be setup to give the raw data in decimal (binary) format or in format, so it is necessary to know how the module is being used. irectlog P is another area where not all values are in. n fact, nearly all of the P parameters are stored in the PL memory as decimal (binary) numbers. NOT: The P 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 P loop. When using the ata View in irectsoft 5, be certain that the proper format is selected for the element to be viewed. The data type and length is 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 n the -more and -more Micro-Graphic M 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. 0 L05 Micro PL User Manual, th dition, Rev. -9