bitmask

How do I compare (AND) two strings which represent a binary mask in mysql?

旧街凉风 提交于 2019-12-23 05:37:08
问题 I have a table in mysql which stores (among other columns) a bitmask as a string, for example: 000100 I'd like to perform a query which will AND these fields together to provide a result that shows when any two mask positions are both true. As an example, consider these three sample records: id name mask == ==== ==== 11 a 000100 12 a 000110 13 a 010000 This query is a self-join. I am looking for records where, for a given name , the same bitmask occurs twice or more. In the above example, the

Finding data gaps with bit masking

痴心易碎 提交于 2019-12-21 21:59:00
问题 I'm faced with a problem of finding discontinuities (gaps) of a given length in a sequence of numbers. So, for example, given [1,2,3,7,8,9,10] and a gap of length=3 , I'll find [4,5,6] . If the gap is length=4 , I'll find nothing. The real sequence is, of course, much longer. I've seen this problem in quite a few posts, and it had various applications and possible implementations. One way I thought might work and should be relatively quick is to represent the complete set as a bit array

SQL Server: varbinary or int to store a bit mask?

偶尔善良 提交于 2019-12-21 07:55:32
问题 Is there any advantage of using int vs varbinary for storing bit masks in terms of performance or flexibility. For my purposes, I will always be doing reads on these bit masks (no writes or updates). 回答1: You should definitely use an INT (if you need 32 flags) or BIGINT (for 64 flags). If you need more flags you could use BINARY (but you should probably also ask yourself why you need so many flags in your application). Besides, if you use an integral type, you can use standard bitwise

How to create mask with least significat bits set to 1 in C

最后都变了- 提交于 2019-12-21 03:46:47
问题 Can someone please explain this function to me? A mask with the least significant n bits set to 1. Ex: n = 6 --> 0x2F, n = 17 --> 0x1FFFF // I don't get these at all, especially how n = 6 --> 0x2F Also, what is a mask? 回答1: The usual way is to take a 1 , and shift it left n bits. That will give you something like: 00100000 . Then subtract one from that, which will clear the bit that's set, and set all the less significant bits, so in this case we'd get: 00011111 . A mask is normally used with

Using sigaction(), c

萝らか妹 提交于 2019-12-21 01:57:29
问题 I was doing a little reading about sigaction() (sources are from my course notes) and I'm not sure I understand this text: The signal mask is calculated and installed only for the duration of the signal handler. By default, the signal “sig” is also blocked when the signal occurs. Once an action is installed for a specific signal using sigaction, it remains installed until another action is explicitly requested. Does this mean that the default signal mask is restored after returning form the

Is there a practical limit to the size of bit masks?

早过忘川 提交于 2019-12-19 03:13:29
问题 There's a common way to store multiple values in one variable, by using a bitmask. For example, if a user has read, write and execute privileges on an item, that can be converted to a single number by saying read = 4 (2^2), write = 2 (2^1), execute = 1 (2^0) and then add them together to get 7. I use this technique in several web applications, where I'd usually store the variable into a field and give it a type of MEDIUMINT or whatever, depending on the number of different values. What I'm

Convert a 64 bit integer into 8 separate 1 byte integers in python

╄→尐↘猪︶ㄣ 提交于 2019-12-18 07:43:22
问题 In python, I have been given a 64 bit integer. This Integer was created by taking several different 8 bit integers and mashing them together into one giant 64 bit integer. It is my job to separate them again. For example: Source number: 2592701575664680400 Binary (64 bits): 0010001111111011001000000101100010101010000101101011111000000000 int 1: 00100011 (35) int 2: 11111011 (251) int 3: 00100000 (32) int 4: 01011000 (88) int 5: 10101010 (170) int 6: 00010110 (22) int 7: 10111110 (190) int 8:

Is there an elegant way to store a dual relationship (i.e. user 1 and user 2 are friends)

谁都会走 提交于 2019-12-18 03:44:12
问题 I've run into the same problem in two different pieces of work this month: Version 1: User 1 & User 2 are friends Version 2: Axis 1 & Axis 2 when graphed should have the quadrants colored... The problem is, I don't see an elegant way, using a RDBMS, to store and query this information. There are two obvious approaches: Approach 1: store the information twice (i.e. two db rows rows per relationship): u1, u2, true u2, u1, true u..n, u..i, true u..i, u..n, true have rules to always look for the

How do I perform a circular rotation of a byte?

被刻印的时光 ゝ 提交于 2019-12-18 03:43:08
问题 I'm trying to implement a function that performs a circular rotation of a byte to the left and to the right. I wrote the same code for both operations. For example, if you are rotating left 1010 becomes 0101 . Is this right? unsigned char rotl(unsigned char c) { int w; unsigned char s = c; for (w = 7; w >= 0; w--) { int b = (int)getBit(c, w);// if (b == 0) { s = clearBit(s, 7 - w); } else if (b == 1) { s = setBit(s, 7 - w); } } return s; } unsigned char getBit(unsigned char c, int n) { return

Is there way to match IP with IP+CIDR straight from SELECT query?

余生颓废 提交于 2019-12-17 21:54:25
问题 Something like SELECT COUNT(*) AS c FROM BANS WHERE typeid=6 AND (SELECT ipaddr,cidr FROM BANS) MATCH AGAINST 'this_ip'; So you don't first fetch all records from DB and then match them one-by one. If c > 0 then were matched. BANS table: id int auto incr PK typeid TINYINT (1=hostname, 4=ipv4, 6=ipv6) ipaddr BINARY(128) cidr INT host VARCHAR(255) DB: MySQL 5 IP and IPv type (4 or 6) is known when querying. IP is for example ::1 in binary format BANNED IP is for example ::1/64 回答1: Remember