“MSX BASIC” COLUMN by Orazio Cacciola (part 3)
The Systems; Binary, Octal and Hexadecimal
The Binary System uses only 2 numbers 0 and 1. It is read from right to left and is a base 2 positional system. To give an example, we want to write the decimal number 151. In Binary it will be: 10010111. We said that it is read by right to left, Therefore: 1+2+4+0+16+0+0+128. Since the calculation will be done with the elevation to the 2nd, the base 2 code will be added to each position if this is turned on, i.e. if it is 1.
If we want to know the correspondence of a binary number and we have the decimal, our MSX uses the function BIN$(decimal number). Remember that this transformed number will be an alphanumeric value. If instead we want to find the binary number from the decimal one, we can use the VAL function: A=VAL(“&B10010111”). Where & is the conversion suffix (not knowing what the correct wording is, I gave this definition) and B stands for binary code. Unfortunately, at least as far as I'm aware, there is no way to calculate 2 or more binary numbers.
The Octal System uses only 8 numbers, from 0 to 7, after which it will start again from 10 to 17 and so on. the 10 in octal corresponds to the 8 decimal. We can say that it is a base 8 positional system. It is a system that is used very little (in many years I have never seen anyone use it), but this does not mean that it is not valid. From what I read, it was mostly used in scientific software.
If we want to convert a decimal number to octal, we will use the OCT$(Decimal Value) function. If vice versa, we will always use the VAL function: A=VAL(“&O Octal Number”). Where, as mentioned above, the & is the conversion suffix and the letter O specifies that it is converting to an octal number. What I said above for calculating binaries also applies to octals.
The Hexadecimal system uses 16 numbers. To fill in the missing numbers that go after the number 9, use the first 6 letters of the alphabet. The numbering is defined as follows: 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F. After the latter we will start again from the number 10 which is equivalent to the decimal number 16. Here too, if we want to convert a decimal number to ESA, we will use the HEX$(Decimal Number) function. As for the other 2 systems, the VAL function is also used for ESAs to find its value in decimal. A=VAL(“&H Hexadecimal Number”), where the H specifies that the number being converted is in ESA.
To conclude, I just wanted to say that it was a very quick and vague explanation, I didn't go into detail. My aim is only to introduce you to the commands and functions of MSX Basic. Every now and then I focus on some topic that is a must to know something more about, but on these it wasn't that important. I refer you to the various books and manuals where the topic is explained in more detail.
One more thing to finish. For those starting to learn this language, it is not very important for programming purposes to know these number systems. In the little programs you start making, they will never be used. But with experience and the desire to delve into more complex programs, knowledge of the latter will be fundamental.
Thanks and see you next time



0 Comments