Questions tagged [bitmask]

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.

738 questions
7
votes
6 answers

Determine which bit is set, for a date, using complex bit masks

I have a bit shift mask that represents days in a week: Sunday = 1 Monday = 2 Tuesday = 4 ... Saturday = 64 I'm using a bitmask because several (at least one) days may be set to 1. The problem Then I get a date. Any date. And based on the…
Robert Koritnik
  • 103,639
  • 52
  • 277
  • 404
7
votes
3 answers

How does if((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { } work?

On this page, I see the following code: if ((attributes & FileAttributes.Hidden) == FileAttributes.Hidden) But I don't understand why it is the way it is. Why attributes & FileAttributes.Hidden)? What does the singular check on attributes actually…
forloop
  • 147
  • 8
7
votes
4 answers

BitMask operation in java

Consider the scenario I have values assigned like these Amazon -1 Walmart -2 Target -4 Costco -8 Bjs -16 In DB, data is stored by masking these values based on their availability for each product. eg., Mask product description 1 …
Anand
  • 1,137
  • 3
  • 9
  • 12
7
votes
1 answer

Recursion vs bitmasking for getting all combinations of vector elements

While practicing for programming competitions (like ACM, Code Jam, etc) I've met some problems that require me to generate all possible combinations of some vector elements. Let's say that I have the vector {1,2,3}, I'd need to generate the…
A. Andevski
  • 437
  • 1
  • 5
  • 17
7
votes
4 answers

Fastest function to set bits to one between two bits in an unsigned integer

I have an algorithm for simulations on supercomputers that will need the use of a lot of bit manipulations. Some operations will need masks and particularly a function like this: template
Vincent
  • 57,703
  • 61
  • 205
  • 388
6
votes
5 answers

I want to calculate the inverse mask for an unsigned char

I would like to calculate an inverse mask for an unsigned char.meaning if the original mask 0xc0 the the inverse mask should be 0x3f.that is to say all the bits should be flipped or inverted.I have tried the below but doesn't seem to be working. int…
liv2hak
  • 14,472
  • 53
  • 157
  • 270
6
votes
2 answers

Why is VkShaderStageFlagBits a bitmask?

In Vulkan you specify the VkPipelineShaderStageCreateInfo's to the VkGraphicsPipelineCreateInfo structure, and presumably there is supposed to be one VkPipelineShaderStageCreateInfo for each shader stage (for example the vertex, and fragment…
nedb
  • 586
  • 1
  • 4
  • 12
6
votes
1 answer

Cannot get didEnd(_contact: SKPhysicsContact) to work properly in swift 4

func didBegin(_ contact: SKPhysicsContact) { var firstBody: SKPhysicsBody var secondBody: SKPhysicsBody if(contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask) { firstBody = contact.bodyA secondBody =…
Marin
  • 12,531
  • 17
  • 56
  • 80
6
votes
1 answer

Get specific bit from uint32

I have a UInt32 variable like 3238844000. Now I want to get the first two bits of this number and the 6 bits after the first two bits. Both bits should be int. Decimal: 3238844000 Binary: 11000001000011001101011001100000 ^^ and Decimal:…
Philies
  • 233
  • 1
  • 4
  • 15
6
votes
1 answer

Searching by bitmask in ActiveRecord

I have a users table with a bitmask field that has a permissions mask in it. Locally, I can determine whether a user has a certain permission by doing a bitmask (UserPermissions&Perm)==Perm. However, I want to be able to issue a find_by_mask or…
Mitch Dempsey
  • 38,725
  • 6
  • 68
  • 74
6
votes
2 answers

Decoding a bitmask from a value in C#

I am trying to decode a bitmask [Flags] public enum Amenities { BusinessCenter = 1, FitnessCenter = 2, HotTub = 4, InternetAccess = 8, KidsActivities = 16, Kitchen = 32, PetsAllowed = 64, Pool = 128, Restaurant =…
239revilo
  • 101
  • 2
  • 10
6
votes
3 answers

Bitwise expansion in C++

here is my problem. I have two short ints in C++: short a; short b; Their bit representation can be put in the form a = a0 a1 a2 a3 a4 ... a15 b = b0 b1 b2 b3 b4 ... b15 Where a0, b0, a1, b1 and so on represent the single bits for the two short…
Matteo Monti
  • 8,362
  • 19
  • 68
  • 114
6
votes
3 answers

How do I perform a circular rotation of a byte?

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…
Manuel
  • 976
  • 3
  • 9
  • 21
6
votes
9 answers

why does this work? (finding odd number in c++)

for (unsigned int i = 1; i <= 100; i++) { if (i & 0x00000001) { std::cout << i<<","; } } why does (and how): if( i & 0x00000001 ) figure out the odd number?
Tom
  • 217
  • 1
  • 5
  • 10
6
votes
3 answers

How to change background color of bitmap to transparent and background should not drag?

I used: Bitmap bitmap= Bitmap.createBitmap(255, 255, Bitmap.Config.RGB_565); Canvas canvas = new Canvas(bitmap); Background color is black.... If I use: Bitmap.Config.ARGB_8888; background color is white... my question is that How to change…
sam786
  • 498
  • 1
  • 4
  • 10