Bitwise and operational

Can someone explain this easier?

The binary representation of 170 is 0000 0000 1010 1010 . The binary representation of 75 is 0000 0000 0100 1011 . Performing the bitwise AND operation on these two values ​​leads to the binary result 0000 0000 0000 1010 , which is decimal 10.

 0000 0000 1010 1010 0000 0000 0100 1011 ------------------- 0000 0000 0000 1010 

This will make me click as soon as I know what is being done. I have a basic understanding of binaries and know a little from the top of my head ... for example, 1, represented in binary format, will be 00000001 , and 2 will be 00000010 , and 3 will be 00000011 , and 4 will be 00000100 and 5 will be 00000101 , and 6 will be 00000110 . Therefore, I understand what happens when you get a number every time.

I also understand what happens when this sql developer subtracts, but something is missing when she uses t-sql code to find the answers ... regarding what is indicated in this link.

http://sqlfool.com/2009/02/bitwise-operations/

0
binary
source share
1 answer

Look at the individual binary digits in your example as columns. If there is 1 in both input rows of a certain column, then there will be 1. for this column. Otherwise, it is 0.

The AND operator can be used to "mask" values. Therefore, if you just need the first four least significant bits of a number, you can And this is from 15, for example:

 0010 1101 1110 1100 0000 0000 0000 1111 ------------------- 0000 0000 0000 1100 <-- the value of the first four bits in the top number 

What happens in the SQL example that you contacted.

 freq_interval is one or more of the following: 1 = Sunday 2 = Monday 4 = Tuesday 8 = Wednesday 16 = Thursday 32 = Friday 64 = Saturday 

Corresponds to bit masks:

 0000 0001 = Sunday 0000 0010 = Monday 0000 0100 = Tuesday 0000 1000 = Wednesday 0001 0000 = Thursday 0010 0000 = Friday 0100 0000 = Saturday 
+2
source share

All Articles