
- •Table of Contents
- •Preface
- •Additional Material
- •Basic Electronics
- •1.0 The Atom
- •1.1 Isotopes and Ions
- •1.2 Static Electricity
- •1.3 Electrical Charge
- •1.4 Electrical Circuits
- •1.5 Circuit Elements
- •1.6 Semiconductors
- •Number Systems
- •2.0 Counting
- •2.1 The Origins of the Decimal System
- •2.2 Types of Numbers
- •2.3 Radix Representations
- •2.4 Number System Conversions
- •Data Types and Data Storage
- •3.0 Electronic-Digital Machines
- •3.1 Character Representations
- •3.2 Storage and Encoding of Integers
- •3.3 Encoding of Fractional Numbers
- •3.4 Binary-Coded Decimals (BCD)
- •Digital Logic, Arithmetic, and Conversions
- •4.0 Microcontroller Logic and Arithmetic
- •4.1 Logical Instructions
- •4.2 Microcontroller Arithmetic
- •4.3 Bit Manipulations and Auxiliary Operations
- •4.4 Unsigned Binary Arithmetic
- •4.5 Signed Binary Arithmetic
- •4.6 Data Format Conversions
- •Circuits and Logic Gates
- •5.0 Digital Circuits
- •5.1 The Diode Revisited
- •5.2 The Transistor
- •5.3 Logic Gates
- •5.4 Transistor-Transistor Logic
- •5.5 Other TTL Logic Families
- •5.6 CMOS Logic Gates
- •Circuit Components
- •6.0 Power Supplies
- •6.1 Clocked Logic and Flip-flops
- •6.2 Clocks
- •6.3 Frequency Dividers and Counters
- •6.4 Multiplexers and Demultiplexers
- •6.5 Input Devices
- •The Microchip PIC
- •7.0 The PICMicro Microcontroller
- •7.1 PIC Architecture
- •Mid-range PIC Architecture
- •8.0 Processor Architecture and Design
- •8.1 The Mid-range Core Features
- •8.2 Mid-Range CPU and Instruction Set
- •8.3 EEPROM Data Storage
- •8.4 Data Memory Organization
- •8.5 Mid-range I/O and Peripheral Modules
- •PIC Programming: Tools and Techniques
- •9.0 Microchip’s MPLAB
- •9.1 Integrated Development Environment
- •9.2 Simulators and Debuggers
- •9.3 Programmers
- •9.4 Engineering PIC Software
- •9.5 Pseudo Instructions
- •Programming Essentials: Input and Output
- •10.0 16F84A Programming Template
- •10.1 Introducing the 16F84A
- •10.2 Simple Circuits and Programs
- •10.3 Programming the Seven-segment LED
- •10.4 A Demonstration Board
- •Interrupts
- •11.0 Interrupts on the 16F84
- •11.1 Interrupt Sources
- •11.2 Interrupt Handlers
- •11.3 Interrupt Programming
- •11.4 Sample Programs
- •Timers and Counters
- •12.0 The 16F84 Timer0 Module
- •12.1 Delays Using Timer0
- •12.2 Timer0 as a Counter
- •12.3 Timer0 Programming
- •12.4 The Watchdog Timer
- •12.5 Sample Programs
- •LCD Interfacing and Programming
- •13.0 LCD Features and Architecture
- •13.1 Interfacing with the HD44780
- •13.2 HD44780 Instruction Set
- •13.3 LCD Programming
- •13.4 Sample Programs
- •Communications
- •14.0 PIC Communications Overview
- •14.1 Serial Data Transmission
- •14.2 Parallel Data Transmission
- •14.4 PIC Protocol-based Serial Programming
- •14.5 Sample Programs
- •Data EEPROM Programming
- •15.0 PIC Internal EEPROM Memory
- •15.1 EEPROM Devices and Interfaces
- •15.2 Sample Programs
- •Analog to Digital and Realtime Clocks
- •16.0 A/D Converters
- •16.1 A/D Integrated Circuits
- •16.2 PIC On-Board A/D Hardware
- •16.3 Realtime Clocks
- •16.4 Sample Programs
- •Index
Number Systems |
|
|
23 |
|
4 |
3 |
5 |
9 |
|
| | | |_________________ |
units |
|||
| | |___________________ |
ten units |
|||
| |_____________________ |
hundred units |
|||
|_______________________ |
thousand units |
The total value is obtained by adding the column weights of each unit:
4000 --- 4 thousand units
300 --- 3 hundred units
+50 --- 5 ten units
9 --- 9 unit
----
4359
2.1.3 Radix or Base of a Number System
In any positional number system the weight of each column is determined by the total number of symbols in the set, including zero. This is called the base or radix of the system. The base of the decimal system is 10 and the base of the binary system is 2. The positional value or weight (P) of a digit in a multi-digit number is determined by the formula:
P = d × Bc
where d is the digit, B is the base or radix, and c is the zero-based column number, starting from right to left. Note that the increase in column weight from right to left is purely conventional. You could construct a number system in which the column weights increase in the opposite direction. In fact, in the original Hindu notation the most significant digit was placed at the right.
In radix-positional terms a decimal number can be expressed as a sum of digits by the formula:
∑di × 10i
i= − mn
where i is the system's range and n is its limit.
2.2 Types of Numbers
By the adoption of special representations for different types of numbers the usefulness of a positional number system can be extended beyond the simple counting function.

24 |
Chapter 2 |
2.2.1 Whole Numbers
The digits of a number system, called the positive integers or natural numbers, are an ordered set of symbols. The notion of an ordered set means that the numerical symbols are assigned a predetermined sequence. A positional system of numbers also requires the special digit zero which, by itself, represents the absence of oneness, or nothing, and thus is not included in the set of natural numbers. However, 0 assumes a cardinal function when it is combined with other digits, for instance, 10 or 30. The whole numbers are the set of natural numbers, including the number zero.
2.2.2 Signed Numbers
A number system can also encode direction. We generally use the + and - signs to represent opposite numerical directions. The typical illustration for a set of signed numbers is as follows:
-9 -8 -7 -6 -5 -4 -3 -2 -1 0 +1 +2 +3 +4 +5 +6 +7 +8 +9
negative numbers <- |
zero |
-> positive numbers |
The number zero, which separates the positive and the negative numbers, has no sign of its own, although in some binary encodings we can end up with a negative and a positive zero.
2.2.3 Rational, Irrational, and Imaginary Numbers
A number system also represents parts of a whole. For example, when a carpenter cuts one board into two boards of equal length we can represent the result with the fraction 1/2; the fraction 1/2 represents one of the two parts which make up the object. Rational numbers are those expressed as a ratio of two integers, for example, 1/2, 2/3, 5/248. Note that this use of the word rational is related to the mathematical concept of a ratio, and not to reason.
The denominator of a rational number expresses the number of potential parts. In this sense 2/5 indicates two of five possible parts. There is no reason why the number 1 cannot be used to indicate the number of potential parts, for example 2/1, 128/1. In this case the ratio x/1 indicates x elements of an undivided part. Therefore, it follows that x/1 = x. The implication is that the set of rational numbers includes the integers, since an integer can be expressed as a ratio by using a unit denominator.
But not all non-integer numbers can be written as an exact ratio of two integers. The discovery of the first irrational number is usually associated with the investigation of a right triangle by the Greek mathematician Pythagoras (approximately 600 BC). The Pythagorean Theorem states that in any right triangle the square of the longest side (hypotenuse) is equal to the sum of the squares of the other two sides.
C
a = 1
b = 1

Number Systems |
25 |
For this triangle, the Pythagorean theorem states that |
|
a2 + b2 |
= c2 |
2 = c2
2 = c × c c = 2
Therefore, the length of the hypotenuse in a right triangle with unit sides is a number that, when multiplied by itself, gives 2. This number (approximately 1.414213562) cannot be expressed as the exact ratio of two integers. Other irrational numbers are the square roots of 3 and 5, as well as the mathematical constants π and e.
The set of numbers that includes the natural numbers, the whole numbers, and the rational and irrational numbers is called the real numbers. Most common mathematical problems are solved using real numbers. However, during the investigation of squares and roots we notice that there can be no real number whose square is negative. Mathematicians of the 18th century extended the number system to include operations with roots of negative numbers. They did this by defining an imaginary unit as follows:
i = −1
The imaginary unit makes possible a new set of numbers, called complex numbers, that consist of a real part and an imaginary part. One of the uses of complex numbers is in finding the solution of a quadratic equation. Complex numbers are also useful in vector analysis, graphics, and in solving many engineering, scientific, and mathematical problems.
2.3 Radix Representations
The radix of a number system is the number of symbols in the set, including zero. Thus, the radix of the decimal system is 10, and the radix of the binary system is 2. Digital electronics is based on circuits that can be in one of two stable states. Therefore, a number system based on two symbols is better suited for work in digital electronics, since each state can be represented by a digit.
2.3.1 Decimal versus Binary Numbers
The binary system of numbers uses two symbols, 1 and 0. It is the simplest possible set of symbols with which we can count and perform arithmetic. Most of the difficulties in learning and using the binary system arise from this simplicity. Figure 2.1 shows sixteen groups of four electronic cells each in all possible combinations of two states.

26 Chapter 2
0 |
0 |
0 |
0 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
0 |
0 |
0 |
1 |
1 |
0 |
1 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
0 |
1 |
1 |
1 |
1 |
0 |
0 |
0 |
1 |
0 |
0 |
1 |
1 |
0 |
1 |
0 |
1 |
0 |
1 |
1 |
1 |
1 |
0 |
0 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
Figure 2-1 Electronic Cells and Binary Numbers
It is interesting to note that binary numbers match the physical state of each electronic cell. If we think of each cell as a miniature light bulb, then the binary number 1 can be used to represent the state of a charged cell (light ON) and the binary number 0 to represent the state of an uncharged cell (light OFF).
2.3.2 Hexadecimal and Octal
Binary numbers are convenient in digital electronics; however, one of their drawbacks is the number of symbols required to encode a large value. For example, the number 9134 is represented in four decimal digits. However, the binary equivalent 10001110101110 requires fourteen digits. In addition, large binary numbers are difficult to remember.
One possible way of compensating for these limitations of binary numbers is to use individual symbols to represent groups of binary digits. For example, a group of three binary numbers allows eight possible combinations. In this case, we can use the decimal digits 0 to 7 to represent each possible combination of three binary digits. This grouping of three binary digits gives rise to the following table:
binary |
octal |
||
0 |
0 |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
1 |
0 |
2 |
0 |
1 |
1 |
3 |
1 |
0 |
0 |
4 |
1 |
0 |
1 |
5 |
1 |
1 |
0 |
6 |
1 |
1 |
1 |
7 |