Binary , hexadecimal and octal values in mysql

bin, hex, mysql, octal

Solution

First of all please give me an advice why we need them during storing information

Computers store data in binary. Sometimes it's useful for us to think in terms of the actual bits that are stored, in which case our familiar decimal system can be a little awkward (as conversions are not straightforward); we could write the bits out in full, but that's often too cumbersome since even quite small numbers take up a lot of space to write (e.g. decimal `24521` is binary `101111111001001`).

Instead, we tend to use bases which are some power of 2, since they're more compact than binary whilst having the property that each 'digit' represents an exact number of bits in the binary representation. For example, a hexadecimal (base-16) digit represents four bits (a "nibble") with the digits `0` through to `F` (decimal `15` / binary `1111`); an octal (base-8) digit represents three bits with the digits `0` through to `7` (binary `111`).

Our earlier example of decimal `24521` would be `5FC9` in hex or `57711` in octal: starting from the right you can see that each digit respectively represents 4 and 3 bits in the above binary representation. Therefore it is (relatively) easy for us humans to visualise the binary representation whilst looking at these compact representations in other bases.

Also which type of values must be stored in marked systems?

I'm not sure what you mean by this. As indicated above, the same values can be represented in all of these systems. In MySQL, we can indicate a binary literal by prepending it with `0b` and a hexadecimal literal by prepending it with `0x`. MySQL does not support octal literals.

anyone can explain how it is calculating it ?

The `<<` operator performs a bitwise left-shift. That is, it shifts the bits of the left-hand operand left by the number of places given by the right-hand operand.

For each position the bits of an integer are shifted left, the value represented by those bits increases two-fold. It's similar to the effect of shifting digits left in our decimal system, whereby values increase ten-fold (for example, 50 shifted one place to the left gives 500, which is a ten-fold increase; in binary `110` (decimal 6) shifted one place left gives `1100` (decimal 12), which is a two-fold increase).

In your case, shifting the bits of the number 50 (i.e. `110010`) two places to the left yields 2 two-fold increases (i.e. a four-fold increase overall): `11001000` is decimal 200.

Problem

I am very interested in working with binary , hexadecimal and octal systems in mysql database. First of all please give me an advice why we need them during storing information , because of ton of information or why ? Also which type of values must be stored in marked systems ? In addition here are bit operator like "<<" here is example => `SELECT 50<<2 AS example;` this gives us result 200 , anyone can explain how it is calculating it ? Thanks for answering :))

Original source

Related problems