Erik Østergaard - Decimal Number System

## Decimal Number System

### Overview - Number Systems

Probably the biggest stumbling block most beginning programmers encounter when attempting to learn assembly language is the common use of the binary and hexadecimal numbering systems. Understanding these numbering systems is important because their use simplifies other complex topics including boolean algebra and logic design, signed numeric representation, character codes, and packed data.

This section discusses several important concepts including the binary, decimal, and hexadecimal numbering systems, binary data organization (into bits, nibbles, bytes, words, and double words), signed and unsigned number systems, arithmetic, logical, shift, and rotate operations on binary values, bit fields and packed BCD (Binary Coded Decimal) data, and the ASCII (American Standard Code for Information Interchange) character set. This is basic material and the remainder of this tutorial depends upon your understanding of these concepts. If you are already familiar with these terms from other courses or study, you should at least skim this material before proceeding to the next chapter. If you are unfamiliar with this material, or only vaguely familiar with it, you should study it carefully before proceeding. All of the material in this chapter is important! Do not skip over any material.

Most modern computer systems do not represent numeric values using the decimal system. Instead, they typically use a binary or two's complement numbering system. To understand the limitations of computer arithmetic, you must understand how computers represent numbers.

Remember how mathematical operations are entered into a computer:

- is used for subtraction
* is used for multiplication
/ is used for division
^ is used to raise to a power

There are four number bases commonly used in programming. These are:

 Name Base Symbol Binary Base 2 B Octal Base 8 Q or O Decimal Base 10 none or D Hexadecimal Base 16 H

### The Decimal Number Base Systems

The Decimal Number System uses base 10. It includes the digits from 0 through 9. The weighted values for each position is as follows:

 10^4 10^3 10^2 10^1 10^0 10^-1 10^-2 10^-3 10000 1000 100 10 1 .1 .01 .001

You have been using the decimal (base 10) numbering system for so long that you often take it for granted. When you see a number like "123", you don't think about the value 123. Instead, you generate a mental image of how many items this value represents. In reality, however, the number 123 represents:

1 * 10^2 + 2 * 10^1 + 3 * 10^0 =

1 * 100 + 2 * 10 + 3 * 1 =

100 + 20 + 3 =

123

Each digit appearing to the left of the decimal point represents a value between zero and nine times power of ten represented by its position in the number. Digits appearing to the right of the decimal point represent a value between zero and nine times an increasing negative power of ten. For example, the value 725.194 is represented as follows:

7 * 10^2 + 2 * 10^1 + 5 * 10^0 + 1 * 10^-1 + 9 * 10^-2 + 4 * 10^-3 =

7 * 100 + 2 * 10 + 5 * 1 + 1 * 0.1 + 9 * 0.01 + 4 * 0.001 =

700 + 20 + 5 + 0.1 + 0.09 + 0.004 =

725.194

#### Working with Logarithms / Udregning ved hjælp af logaritmer

A logarithm is used when working with exponentiation. We all learned that the formula `X = YZ` means take the value `Y` and multiply it by itself the number of times specified by `Z`. For example, `23 = 8` (`2*2*2`). The value `Z` is the exponential value of the equation. As long as you know what the `Y` and `Z` values are in the equation, it is easy to calculate the value of `X`. / En logaritme bruges, når der udregnes med eksponent. Vi lærte alle, at formlen `X = YZ` betyder, tag værdien `Y` og multiplicer (gang) den med sig selv antallet af gange angivet af `Z`. For eksempel, `23 = 8` (`2*2*2`). Værdien `Z` er eksponentiel-værdien i ligningen. Så længe man kender, hvad `Y` og `Z` værdierne er i ligningen, er det nemt at beregne værdien af `X`.

Unfortunately, you may not always know the value of `Y` and `Z`. How do you determine `Z` if you know the value of `X` and `Y`? This is when you use a logarithm. A logarithm is the exponent value that indicates the number of times the value `Y` needs to be multiplied by itself to get the value `X`. The value that is multiplied (`Y`) is considered to be the base of the formula. / Uheldigvis kender man ikke altid værdien af `Y` og `Z`. Hvordan bestemmer man `Z`, hvis man kender værdien af `X` og `Y`? Det er da, man bruger en logaritme. En logaritme er eksponent-værdien, som angiver antallet af gange værdien `Y` behøver at blive multipliceret (ganget) med sig selv for at få værdien `X`. Værdien som er multipliceret (ganget) (`Y`) betragtes som grundtallet i formlen.

There are two basic types of logarithms: common and natural. A common logarithm uses a value 10 as the base value. Therefore, in the basic formula for exponentiation above, `X = YZ`, the value of `Y` is 10, and `Z` is the number of times that `Y` needs to be multiplied by itself to return the value indicated by `X`. / Der er to grundlæggende typer af logaritmer: sædvanlig og naturlig. En sædvanlig logaritme bruger en værdi 10 som grundtal. Derfor i den grundlæggende eksponent-formel ovenfor, `X = YZ`, er værdien af `Y` 10, og `Z` er antallet af gange som `Y` behøver at blive multipliceret (ganget) med sig selv for at returnere værdien angivet af `X`.

Natural logarithms use a base value of approximately 2.71828182845905, normally referred to as `e`. The mathematical notation `e` is Euler's constant, the base of natural algorithms, made common by the mathematician Leonhard Euler (Basel, Switzerland April 15, 1707 - Russia September 18, 1783). VBScript provides two functions for working with logarithms: `Exp()` and `Log()`. Each of these functions assumes that the base value is `e`. The `Log()` function returns the natural logarithm of the supplied numeric expression, and the `Exp()` function raises the supplied numeric expression to `e`. The similar methods in JavaScript is called: `Math.exp()` and `Math.log()`. / Naturlige logaritmer bruger et grundtal på tilnærmelsesvis 2,71828182845905, i reglen henvist til som `e`. Den matematiske notation `e` er Eulers konstant, de naturlige algoritmers grundtal, gjort alminding af matematikeren Leonhard Euler (Basel, Schweiz 15. april 1707 - Rusland 18. september 1783). VBScript har to funktioner til udregninger med logaritmer: `Exp()` og `Log()`. Hver af disse funktioner antager, at grundtallet er `e`. `Log()` funktionen returnerer den naturlige logaritme til det leverede numeriske udtryk, og `Exp()` funktionen opløfter det leverede numeriske udtryk til `e`. De lignende metoder i JavaScript kaldes: `Math.exp()` og `Math.log()`.

It is possible to use these VBScript functions or JavaScript methods if you have a different base value by using a simple formula. By dividing the natural log of the desired number (`X`) by the natural log of the desired base (`Y`), you can determine the desired logarithm value (`Z`) in VBScript: `Z = Log(X) / Log(Y)` or similar in JavaScript: `Z = ((Math.log(X)) / (Math.log(Y)));`. / Det er muligt at bruge disse VBScript funktioner eller JavaScript metoder, hvis man har et andet grundtal ved at bruge en simpel formel. Ved at dividere den naturlige log til det ønskede tal (`X`) med den naturlige log til det ønskede grundtal (`Y`), kan man bestemme den ønskede logaritme-værdi (`Z`) i VBScript: `Z = Log(X) / Log(Y)` eller lignende i JavaScript: `Z = ((Math.log(X)) / (Math.log(Y)));`.

##### JavaScript comments: / JavaScript bemærkninger:

The custom function `Pow2(NumDbl)`, which returns the base to an exponent power of 2, and the custom function `Log2(NumDbl)`, which calculates base-2 logarithms, can be seen in this page's source code. They uses respectively the JavaScript `Math.pow()` method, which returns base to the exponent power, that is, base exponent, and a formula based on the JavaScript `Math.log()` method, which returns the natural logarithm (base E) of a number. / Funktionen lavet på bestilling `Pow2(NumDbl)`, som returnerer grundtallet til en eksponent potens af 2, og funktionen lavet på bestilling `Log2(NumDbl)`, som beregner grundtal-2 logaritmer, kan ses i denne sides kildekode. De bruger henholdsvis JavaScript `Math.pow()` metoden, som returnerer grundtallet til en eksponent potens, det vil sige grundtal eksponent, og en formel baseret på JavaScript `Math.log()` metoden, som returnerer den naturlige logaritme (grundtal E) af et tal.

##### See the JavaScript by View Source / Se JavaScript'et via Vis Kilde

You can see the JavaScript by using View Source. / Man kan se JavaScript'et ved at bruge Vis Kilde.

##### My Sources / Mine kilder

Sources: Various books, the Internet, and various encyclopedias.

Kilder: Forskellige bøger, internettet og forskellige leksikoner.

### Computer Data Representation and Number Systems / Computer data repræsentation og talsystemer

 ©1997 - 1999 Erik Østergaard, Copenhagen, Denmark.