First of all, give me advice on why we need them when storing information.
Computers store data in binary format. Sometimes it’s useful for us to think about the real bits that are stored, in which case our familiar decimal system may be a bit uncomfortable (since the conversions are not simple); we could write the bits in full, but this is often too cumbersome, since even fairly small numbers take up a lot of recording space (for example, decimal 24521
is binary 101111111001001
).
Instead, we tend to use bases that are some power of 2 because they are more compact than binary ones but have the property that each “digit” represents the exact number of bits in the binary representation. For example, a hexadecimal (base-16) digit represents four bits ("nibble") with digits from 0
to F
(decimal 15
/ binary 1111
); the octal (base-8) digit represents three bits with the digits 0
to 7
(binary 111
).
Our previous decimal example 24521
would be 5FC9
in hexadecimal or 57711
in octal: starting from the right side you can see that each digit represents 4 and 3 bits respectively in the binary representation above. Therefore, it’s (relatively) easy for us to visualize the binary representation of people by looking at these compact representations in other databases.
And what type of values should be stored in marked systems?
I'm not sure what you mean by that. As indicated above, the same values can be represented in all of these systems. In MySQL, we can specify a binary literal by adding it with 0b
and a hexadecimal literal by adding it with 0x
. MySQL does not support octal literals.
can anyone explain how he calculates it?
The <<
operator performs a bitwise left shift. That is, it shifts the bit of the left operand to the left of the number of places specified by the right operand.
For each position, the bits of the integer are shifted to the left, the value represented by these bits is doubled. This is similar to the effect of shifting the digits left in our decimal system, and the values increase tenfold (for example, 50 shifted one place to the left gives 500, which is a tenfold increase, in binary format 110
(decimal value 6)), shifted by one place on the left gives 1100
(decimal 12), which is a double increase).
In your case, the shift of the bits of the number 50 (i.e. 110010
) in two places on the left gives 2 times twice (i.e. the total increase is four times): 11001000
- decimal 200.