Binary numbers and types of variables

The numeral system that the people use is the decimal system, this is, Exist 10 different symbols which are combined to make any number. The 10 symbols are the numbers 0 to 9. In order to represent the decimal number 121, the following operation is done:

1×102+2×101+1×100=100+20+1=121

In this example can see that, in order to obtain the number, the position of each symbols (that can be any between 0 to 9) in multiplied by the base (10 for decimal system, for the 10 symbols) to the power of position of the symbol begun since the number 0, in others words, the symbol on the position zero is multiplied by 1 (100 =1), the symbol on the second position is multiplied by 10 (101=10), the symbol in the third position is multiplied by 100 (102=100) and so on.

The binary system works in similar way to the decimal system, but in the in the binary system the number de symbols is two, 0 and 1, for example, to represent the number 121 in binary, the following operation is done:

1×26+1×25+1×24+1×23+0x22+0x21+1×20= 64+32+16+8+0+0+1=121

The representation of the number 121 in binary is 1111001b, the “b” means that the representation of the number is in binary and differentiates it one million, one hundred eleven thousand, one in decimal. In this point, it can be asking how it has obtained the patron of 1’s and 0’s to represent the number 121 in binary. There are several ways; one very simple is to set 1’s from left to right progressively. If it put a 1 on a determined position and the value is higher that the desired value, then, the value on this position must be a 0. For the number 121, if it begins with a 1 on the position 7, the value obtained is 127, which is greater than 121, for this reason it begin with a 1 on the position 6. The next table summarizes the procedure.

Position

Cumulative sum

Value in the position

6

2position=26=64

1

5

64+32=96

1

4

96+16=112

1

3

112+8=120

1

2

120+4=124 > 121

0

1

120+2=122 >121

0

0

120+1=121

1

 

Each position (or digit) of a binary number also is called bit, in the case of the example above, the number 121 is represented with 7 bits. The number of bits is important because it determinate the range of values that can have a binary number, for example, an 8-bits number can have a value between 0 and 255 (2n-1, where n is the number of bits). Since the point of view electronic, the fact each digit has only two values is very important, this gives simplicity to each digit that can be represented as a switch open or closed, or with a cut-off o saturated transistor, among others.

La combinaciones de 1’s y 0’s también sirven para representar códigos, como por ejemplo el código ASCII. Por ejemplo el número 01111001b representa el número 121, representa la letra “y” en el código ASCII y representa el número 79 en código BCD entre otros.

The importance of the binary numbers in the PLC use is in the fact that the microprocessors with which are constructed executing its operations using as arguments binary variables. These binary variables can be of different types, the most used are: Boolean (or bit), integers, float point, characters and string of characters. The integers and float point variables are called analog variables.

The boolean variables, also called bit or logical, are binary representations with only one bit or digit, in such sense, only can have the values 0 and 1, that normally are interpreted as false o true respectively.

The integer variables are memory registers that can keep numbers of n-bits, where n, typically, is multiple of 2, for example 4, 8, 16, 32 and 64 bits. The number of bits, as it was mentioned before, determines the range of the values that the variable has. The binary numbers can be positives including the zero, in this case the code is called pure binary, or positives, negatives and zero, in this case the code is called 2-complement binary. The next table shows the range for the integers according to the number of bits.

Number de bits Range (binary) Range (binary 2-complement)
4 (nibble) 0 to 15 -8 to 7
8 (byte) 0 to 255 -128 to +127
16 0 to 65,535 -32,768 to +32,767
32 0 to 4,294,967,295 -2,147,483,648 to +2,147,483,647
64 0 to 18,446,744,073,709,551,615 -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807

 

The point float variables, also called real, have decimals. The representation of a float point is done with standards as IEEE 754. With this standard and simple precision, numbers from -1.17549449×10-38 to 3.40282346×1038 can be represented.

A character is a symbol of the ASCII table (letters, numbers, symbols and control characters) represented with 8 bits. If 2 or more characters are concatenated is called string of characters and is used to locate words and phrases.

Leave a Comment

Your email address will not be published. Required fields are marked *