03.12.2012 Views

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

C++ for Scientists - Technische Universität Dresden

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Finite World of Computers<br />

Chapter 8<br />

8.1 Mathematical Objects inside the Computer<br />

First natural numbers N are introduced and the data types available in a programming language<br />

used to represent them. The difference between a single digit, and their connection to the used<br />

base is an important concept in computer science.<br />

A number is represented by several single digits, with each digit being a factor <strong>for</strong> a corresponding<br />

power of the base. The number is only complete when both the base and all of the digits are<br />

known. To use an example, the digit sequence 123 is calculated with the corresponding base,<br />

e.g. base = 10:<br />

12310 = 1 · 10 2 + 2 · 10 1 + 3 · 10 0<br />

If the base is switched, e.g. base = 4, then the following numbers are derived:<br />

1234 = 1 · 4 2 + 2 · 4 1 + 3 · 4 0 = 2710<br />

One of the drawbacks of the representation of numbers within the computer is the fact that the<br />

built-in types such as int and long can only use a finite number of bits and are hence limited<br />

in their range (the int can be omitted), e.g.:<br />

short int: -32768 +32767<br />

long int: -2147483648 +2147483647<br />

unsigned long int: 0 +4 294 967 295<br />

As can be seen the maximum number of countable items is restricted. If, as an example, a<br />

program has to count the living humans on earth we have to switch to another number concept,<br />

either floating point or a decimal data type. A plain and simple arbitrary digit number container<br />

can be implemented by:<br />

class big number{<br />

long base;<br />

std::vector digits;<br />

public:<br />

225

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!