1

Topic: Bit values

Good afternoon.
There is a field, type smallint, name it NoPay, in table Family
The decimal number is stored in this field.
Actually this bit-by-bit value from 8 bits: 0 or 1. Sequence - 7654 3210
1. Whether probably request to select all records at which 1 it is installed 1, i.e. a certain sign is installed.
2. Whether probably request to select all records at which 2 it is installed 1, i.e. a certain sign is installed.
3. Whether probably request to select all records at which 3 it is installed 1, i.e. a certain sign is installed.
If it is possible, show please on a specific example:
select NoPay from Family where....
--------------------------
Firebird 3.0.1.32609;
IBExpert 2017.3.12.1;
Windows 10 32-bit;
4Gb RAM;
SSD 512Mb + HDD 1 Tb;
Default settings
Development environment:
Delphi XE2 + FIBPlus 7.4

2

Re: Bit values

https://firebirdsql.org/refdocs/langref … n_and.html

3

Re: Bit values

Ivan_Pisarevsky;
I found it and read. But did not understand as sad
Help an example please

4

Re: Bit values

akrush wrote:

Actually this bit-by-bit value from 8 bits: 0 or 1. Sequence - 7654 3210

It that, bit values? What does "sequence" mean? It that, numbers of bits?
Then 2^7 + 2^6 + 2^5 etc.
https://ru.wikipedia.org/wiki/__

5

Re: Bit values

Greetings.

akrush wrote:

If it is possible, show please on a specific example:
select NoPay from Family where....

select NoPay
from Family
where bin_and (NoPay, 0x01) = 0x01 - for 0th bit
where bin_and (NoPay, 0x02) = 0x02 - for 1st bit
where bin_and (NoPay, 0x04) = 0x04 - for 2nd bit

Yours faithfully, Polesov.

6

Re: Bit values

Polesov;
Thanks, I will try.
Still a question: we assume at me in bits 4-7 a quantity, for example 6 (it is 0111) is stored. And how this function to check up this number?

7

Re: Bit values

akrush wrote:

a quantity is stored in bits 4-7, for example 6 (it is 0111)

0111 is 7. Because bits go from right to left. But even if they would go from left to right it would be 14.
And in 4-7 bits it can not be stored in any way neither 7, nor 6.
Because
4 bits - 2^4 = 16
5 bits - 2^5 = 32
6 bits - 2^6 = 64
7 bits - 2^7 = 128
p.s. I consider that only in 2018 such probably to hear from the programmer.

8

Re: Bit values

kdv wrote:

And in 4-7 bits it can not be stored in any way neither 7, nor 6.

Perhaps certainly. Any number which gets into 4 bits can be stored in 4 bits smile
It is an information representation question in the given specific case. Perhaps it there stores four two-bit numbers in 8 bits. Or two three-bit. Or still as. It is not forbidden.

9

Re: Bit values

akrush wrote:

still a question: we assume at me in bits 4-7 a quantity, for example 6 (it is 0111) is stored. And how this function to check up this number?

bit_shr (NoPay, 4)

10

Re: Bit values

Greetings.

akrush wrote:

still a question: we assume at me in bits 4-7 a quantity, for example 6 (it is 0111) is stored. And how this function to check up this number?

We recognize that bits are numbered from right to left since zero.
If value has type SMALLINT - 16 bits, INTEGER - 32 bits.
For SMALLINT us the bits marked 1 interest:

0000000011110000

How to learn, what in the specified bits number 6 contains?
It is necessary to shift bit value to the right on 4, to select on a mask of 4 bits and to compare:

bin_and (bin_shr (NoPay, 4), 0x0F) = 6

P.S. Generally 6 = 0110b :-)
Yours faithfully, Polesov.

11

Re: Bit values

kdv wrote:

p.s. I consider that only in 2018 such probably to hear from the programmer.

Character of this bit information still is wildly interesting to me. There is one suspicion.

12

Re: Bit values

Polesov, and we will solve for  ? smile

13

Re: Bit values

the teddy bear wrote:

still is wildly interesting To me character of this bit information.

There is a difference? The author does not understand, how the bit mask works, and all there to save on matches.
The author, how many billions records it is necessary to hill, that disk saving on these bits became noticeable?

14

Re: Bit values

Ivan_Pisarevsky;
Alas bits get by right of succession at Clarion conversion in Ogneptitsa.
In tables a heap of fields with bit-by-bit "encryption". Here also it is necessary  to paint them on different columns.
Always it did by search every line + Delfi.
Asked a question, and whether it is possible at once request.
Essentially answer already received - it is possible.
As I understood it is possible even at once update to write which a move all registers.
I will smoke "now a bamboo" and "to gnaw a science granite", to understand as these bit masks work.
Thanks for examples. Alas questions will appear still and I will set them

15

Re: Bit values

rdb_dev wrote:

Polesov, and we will solve for  ? smile

Really you think, what if to the person something is not clear, is a student to which laziness in something to understand?
Yes different numeration systems were heavily given and given to me.
But it not an occasion to hang up a brand "" and ""

16

Re: Bit values

akrush> In tables a heap of fields with bit-by-bit "encryption".
akrush> Here also it is necessary  to paint them on different columns.
And, so you from   try to make it.
This business gallant, may god speed you. Only do not forget
Then  that it did not turn out that
Translated working (though also awful)  (DB)
In beautiful, but wrong.

17

Re: Bit values

Gadzhimuradov Rustam;
I check. I have a control row list

18

Re: Bit values

Rustam wrote:

akrush> In tables a heap of fields with bit-by-bit "encryption".
akrush> Here also it is necessary  to paint them on different columns.
And, so you from   try to make it.
This business gallant, may god speed you. Only do not forget
Then  that it did not turn out that
Translated working (though also awful)  (DB)
In beautiful, but wrong.

In a file-server bases, probably, normal behavior. Saved on the size of the basis, and indexes and so  worked. Correctly does that the data scheme changes. Offset!

19

Re: Bit values

akrush if I am not right, I apologize! smile
With numeration systems all is elementary!
In decimal numeration on the base 10 it is had following discharges of number:
Discharge 0 (units): N*100
Discharge 1 (tens): N*101
Discharge 2 (hundreds): N*102
Discharge 3 (thousand): N*103
Etc., where N - value in discharge from 0 to 9
In binary numeral system on the base 2 it is had following discharges:
Discharge 0 (units): N*20
Discharge 1 (twains): N*21
Discharge 2 (quadruples): N*22
Discharge 3 (eights): N*23
Etc., where N - value in discharge 0 or 1
As we see, the binary system is even easier and installed in 1 bits in a machine word (16 bits) it is possible  in decimal system under the following table:

 +-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+
|32768|16384 | 8192 | 4096 | 2048 | 1024 | 512 | 256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+

20

Re: Bit values

rdb_dev;
Yes a lie! If in the first and second bit there are units in decimal system it is 3 (three). Without bit-by-bit operations anywhere!

21

Re: Bit values

KreatorXXI, what "lie"? If, for example, in are installed in 1 discharges 0,3,5,10, it 1+8+32+1024=1065

22

Re: Bit values

akrush wrote:

Ivan_Pisarevsky;
Alas bits get by right of succession at Clarion conversion in Ogneptitsa.
In tables a heap of fields with bit-by-bit "encryption". Here also it is necessary  to paint them on different columns.

I and thought. Through it it is necessary to transit almost to all who had time to turn out something useful on plane DB. I advise still to think of organizing normal structure - to reduce values in non-numerical columns in tables-directories and in columns of work tables to use references.

23

Re: Bit values

rdb_dev;
It is truth. What for the table? I simply did not understand its assignment. Probably, simply elements. Which all know. But they are inapplicable in the modern real life.

24

Re: Bit values

KreatorXXI that to the person absolutely not familiar with elements of binary numeration system, it was easier to be guided - what bit of a machine word corresponds to what decimal number without calculator usage in a mode "Programmer".
> But they are inapplicable in the modern real life.
Why are inapplicable? Something in bit numeration system in essence changed? For understanding of principles quite approaches.

25

Re: Bit values

rdb_dev wrote:

what bit of a machine word corresponds to what decimal number

For a bit mask useless knowledge.

rdb_dev wrote:

For understanding of principles quite approaches.

to the Person it is necessary  , instead of general principles to run in, like as.