Bitmask is a technique used to isolate specific bits in a byte in order to work only on the desired ones. They are used in IP addresses to separate the network prefix and the host number for example.
Questions tagged [bitmask]
738 questions
0
votes
1 answer
Using bitmasks to extract binary representation of hex causes errors
So I wrote this function, create_room_connections(struct *, unsigned int) and it takes as input a pointer to a structure, and an unsigned int.
Now, that unsigned int is actually a hexadecimal number, and the purpose of this function is to mask the…

tofu
- 125
- 1
- 3
- 11
0
votes
1 answer
java transfer bits at offset and length from byte to int
I am trying to transfer a certain number of bits in a byte to the beginning of an int but its not working out as planned.
public int transfer(byte b, int offset, int len, int dest, int bitsInUSe){
byte mask = (byte) ((byte) ((1 <<…

daedalus
- 105
- 2
- 10
0
votes
0 answers
Fast bit gathering with mask
I'm trying to figure out the fastest way to copy bits according to a given mask, and put them together, for example:
| | |
x = 0x01110001
| | |
mask = 0x00100101
| | |
result=0x101----- (- doesn't…

MoonBun
- 4,322
- 3
- 37
- 69
0
votes
1 answer
Accessing individual objects that all have the same categoryBitMask
I have several game world objects the player needs to interact with individually upon his physicsBody.categoryBitMask contacting them. Instead of using separate categoryBitMasks for each individual object (object count surpasses categoryBitMask's…

Krekin
- 1,516
- 1
- 13
- 24
0
votes
1 answer
What is the maximum integer it is safe to use in a Javascript bitmask flag value?
This is mostly just a sanity-check.
Mozilla says that
The operands of all bitwise operators are converted to signed 32-bit
integers in two's complement format.
and that
The numbers -2147483648 and 2147483647 are the minimum and the maximum
…

Brian Rak
- 4,912
- 6
- 34
- 44
0
votes
1 answer
Best way to track list of enabled services using bitmask in sql server?
I'm trying to come up with a simple way to track a list of enabled services for customers in a 2008 MS SQL Server database.
There are 256 possible enabled services that a customer can subscribe.
For each customer I need to know which services are…

Jack Allen
- 103
- 1
- 7
0
votes
3 answers
Apply ImageView as Mask To Another ImageView
I have read the posts on applying an .png as an ImageView mask (Android how to apply mask on ImageView?) but Im curious if it can be done without having a .png file.
I have an ImageView that takes up the whole screen. What I want to is to mask a…

Aggressor
- 13,323
- 24
- 103
- 182
0
votes
2 answers
F# HashCode to enum conversion
I have an enum of bit-masked error codes with a string representation and an binary int representation:
type ErrorCodes =
| NoError = 0
| InvalidInputError = 1
| AuthenticationFailedError = 2
| InvalidArgumentError = 4
|…

user3685285
- 6,066
- 13
- 54
- 95
0
votes
2 answers
Using a bitmask and if statement
I am trying to allow multiple cases to run in a switch statement. I have a bitmask as follows:
#define SHOOT_ROCKET 2 << 16
#define MOVE_FORWARD 3 << 16
Later, I do
switch (int game_action)
and I have
case SHOOT_ROCKET:
result =…

user3526827
- 153
- 1
- 1
- 9
0
votes
2 answers
Simplifying a bit set algorithm attempt
Trying to simplify this working but lengthy code for an assignment involving bit array manipulation. What I have so far for the set function(sets the bit at index in the array to 1):
// set bit with given index to 1
void BitArray::Set (unsigned…

Tyler Kelly
- 564
- 5
- 23
0
votes
1 answer
Checking bitmask: x & b != 0 VS x & b == b
Suppose x is a bitmask value, and b is one flag, e.g.
x = 0b10101101
b = 0b00000100
There seems to be two ways to check whether the bit indicated by b is turned on in x:
if (x & b != 0) // (1)
if (x & b == b) // (2)
In most circumstances it…

franklsf95
- 1,182
- 12
- 23
0
votes
1 answer
Generate only those binary strings of length n with maximum k consecutive zeros
What is the most efficient way to generate only those binary strings of length n, which have a maximum of k consecutive zeroes.
For eg :- if n = 3, k = 2:
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
and not 000
Note : I need this method for my…

Ashish Shukla
- 3
- 3
0
votes
1 answer
How to decode bit mask in sql
For example 10 = 2+8 = 2^1 + 2^3
In the query, How can I select it when I want the code contains 2^1 or 2^3?

user3516947
- 33
- 4
0
votes
3 answers
How do you use bitwise operators, masks, to find if a number is a multiple of another number?
So I have been told that this can be done and that bitwise operations and masks can be very useful but I must be missing something in how they work.
I am trying to calculate whether a number, say x, is a multiple of y. If x is a multiple of y great…

lauren
- 11
- 4
0
votes
2 answers
Efficient way to bit mask every number of a file list using bitwise operators
I have a file which contains a list of numbers defined as follow :
var1=0x00000001
var2=0x00000002
var3=0x00000008
var4=0x00000020
var5=0x00000040
var6=0x00000080
var7=0x00000100
var8=0x00000200
var9=0x00000400
var10=0x00000800…

ogs
- 1,139
- 8
- 19
- 42