Number systems; representation of numbers


Positional number systems

In digital computers, data is generally represented as a sequence of binary digits, e.g. in the form of binary numbers. Since binary numbers are difficult to handle, we usually display them in the hexadecimal number system (i.e. in the positional number system with base 16) as hexadecimal numbers.

A number system (or number representation system) defines uniform rules which determine how we represent numbers by a series of digits.

In general, numbers in a number system with base 'b' can be described or represented by the following formula:
egy szám általános alakja a 'b' alapú számrendszerben

Examples:

(1) a real number in the decimal number system (b=10):
    314.610 = 3*102+1*101+4*100 + 6*10−1

(2) an integer in the binary number system (b=2):
    1010112 = 1*25+1*23+1*21+1*20 = 4310

(3) a real number in the binary number system (b=2):
    101011.1012 = 1*25+1*23+1*21+1*20 + 1*2−1+1*2−3 = 43.62510

(4) an integer in the hexadecimal number system (b=16):
    1C416 = 1*162+12*161+4*160 = 45210

(5) a real number in the hexadecimal number system (b=16):
    1C4.416 = 1*162+12*161+4*160 + 4*16−1 = 452.2510



The concept of algorithm

In computer science, or in general, in the ubiquitous and rapidly evolving information and communication technology (IKT), the concept of algorithm is fundamental.

An algorithm is a prescribed set of instructions for the solution of a given problem (or a group of similar problems) in a finite number of steps. The instructions are executed one by one in a well-defined order. A well-known example of an algorithm is the performance of a calculation (e.g. an addition).

The algorithms that are important to us are those that can be described ("encoded") with the help of a computer program. In that case, the instructions of the algorithm are described with statements in a given programming language to perform specific actions or operations for each step of the algorithm.

In this chapter we will learn about several algorithms related to number systems. In addition, we will provide a number of programs for the formal description of those algorithms. The most important components of these programs are reviewed below.

The examples here are given in the JavaScript programming language. These programs use only the very basic statements of the JavaScript language. To get to know the language more thoroughly, it is strongly recommended to study the following materials which are ideal for self-study:

JavaScript Tutorial (2022-09-27)
JavaScript Algorithms and Data Structures (2022-10-02)

Note that the advanced features of the JavaScript language require the knowledge of the basics of the HTML language.


A simple example: Display the first 'n' natural numbers.

The simplest JavaScript programs are built from the following statements:

The three most important control structures that determine the execution order of the statements are as follows:

The above control structures can be excellently illustrated with the help of flowcharts as follows: (cf. Essential Programming | Control Structures | by Diego Lopez Yse | Towards Data Science, 2022-10-09):

the 'if' control structure the 'while' control structure


Another example: Converting a binary number to a decimal number.

In the following, we present specific algorithms related to number systems.

In most cases, the description of the algorithms is also presented with short JavaScript programs. An online JavaScript interpreter that can be used to try the example programs can be accessed as follows:

Online JavaScript Interpreter by Peter Jipsen, Chapman University (January 2013).
http://math.chapman.edu/~jipsen/js/ (2020-11-19)

Note: because the link above is currently not working, please use the link here.

The flowcharts illustrating the JavaScript programs can be displayed using the online web application below:

Live code editor. Created by Bogdan Lyashenko.
https://bogdan-lyashenko.github.io/js-code-to-svg-flowchart/docs/live-editor/index.html (2022-10-02)


Boda István, 2024-2025.