Questions tagged [bit-masks]

bitmasks are data used for bitwise operations.

54 questions
2
votes
3 answers

How to ignore bits in a variable

I would like to know how to delete bits in a bit value. I receive a 10 bits value (bit 0 to bit 9) and I have to send a variable which ignore bit 0, bit 2, bit 4 and bit 6 of the received value then my variable will be : bit 987531. How can I do ? I…
2
votes
2 answers

Physics contacts in SpriteKit

Is it possible to explain how bitmasking works for just this simplistic situation: A big (blue) ball. Contact BitMask 0b0001 A medium (red) ball. Contact BitMask 0b0010 A small (white) ball. Contact BitMask 0b0100 They have no collisions…
Confused
  • 6,048
  • 6
  • 34
  • 75
2
votes
1 answer

sprite kit swift, detecting collision for game over

I am currently making my first game. I have a collision function ballCollideWithWall(_:Ball:) which is called as expected, but the game over scene is not presenting. I verified that the collision function is called by using NSLog. // game over…
joey2308
  • 21
  • 1
2
votes
1 answer

64bit bitmask and javascript

I am currently fighting with a javascript problem where I have a 62bit bitmask that should be used as filter. I used the snippet from here but I cant get it to work for some cases. How to do bitwise AND in javascript on variables that are longer…
Max Melcher
  • 200
  • 1
  • 12
2
votes
1 answer

Bitmasking small numeric values over a byte array without wasting space in c#?

I'm trying to extend this topic a bit by expanding it to cover 5-bit values packed into a byte[] data structure. The specific objective I'm trying to achieve would be to store a total of 128 5-bit (0-31) numeric values in a 80-byte array with a…
CoryG
  • 2,429
  • 3
  • 25
  • 60
2
votes
1 answer

Is is possible to set an NS_OPTION as a value in an NSMutableDictionary?

I'm trying to set up a dictionary of rules; the keys are strings, and I'd love to set up the values to be bitmaps. I'm using NS_OPTION to declare items as such : typedef NS_OPTIONS(NSInteger, PermittedDirection) { LeftDirection = 1 << 0, …
pikovayadama
  • 808
  • 2
  • 8
  • 26
2
votes
1 answer

what is diffrence bettween masking a char with 0xFF and casting (unsigned char)

unsigned char Mid; if( (data[2]) == 0x9A){ Mid = data[5]; if( (Mid == 1) || (Mid == 2) || (Mid == 3) ) return(Mid); The code above gives: warning: comparison is always false due to limited range of data type error as I…
roll
  • 125
  • 13
1
vote
1 answer

32-bit int struct bits don't seem to match up (nodejs)

I have a file that defines a set of tiles (used in an online game). The format for each tile is as follows: x: 12 bits y: 12 bits tile: 8 bits 32 bits in total, so each tile can be expressed as a 32 bit integer. More info about the file…
samstr
  • 190
  • 2
  • 7
1
vote
1 answer

How to translate from decimal to bit-mask?

I have a ACLs system previously built by someone else and I am trying to understand how bit-masking works there. I have this 4 constants defined: const NONE = 0; const READ = 1; const WRITE = 2; const UPDATE = 4; const DELETE = 8; Then in DB I am…
ReynierPM
  • 17,594
  • 53
  • 193
  • 363
1
vote
1 answer

What is the optimal way to choose a set of features for excluding items based on a bitmask when matching against a large set?

Suppose I have a large, static set of objects, and I have an object that I want to match against all of them according to a complicated set of criteria that entails an expensive test. Suppose also that it's possible to identify a large set of…
samgak
  • 23,944
  • 4
  • 60
  • 82
1
vote
1 answer

Multiple collision bitmasks on 1 physics object?

Can one physics body have 2 different collision bit masks? I have this code: bo.physicsBody?.collisionBitMask = noneCategory But I'd like "bo" to also collide with "bumperCategory". So, I imagine it could look something like this: …
Alan Scarpa
  • 3,352
  • 4
  • 26
  • 48
1
vote
1 answer

Bitmask Permissions - Extending/Revoking permissions

I have a bitmask permissions + roles set: { EDIT: '1', DELETE: '2', ADD: '4', VIEW: '8', } I'm looking for the simplest way to Extend and Revoke user permissions using bitwise operations. For example a user has 7 set as permissions…
Maruf
  • 890
  • 3
  • 10
  • 21
1
vote
1 answer

Rails: A database-independent datatype that's suitable for bitwise operations

I have a Rails app with a couple resources that I need to run queries on that involve bitwise operations. Right now, I'm using PostgreSQL, and I created a migration for my 'user' model that uses the postgres-specific 'BIT VARYING' datatype, since…
Andrew
  • 2,425
  • 2
  • 24
  • 35
1
vote
1 answer

Convert long string to integer without parseLong or parseInt

Here's is the situation ... i have a binary file which contains 32-bit binary strings of characters (e.g 1011011100100110101010101011010 ) and i want to convert this to integer ... I have already tried to do it with parse-Int but if the most…
1
vote
0 answers

Bitmask comparisons Mongo queries

For a Blog webapp, I am trying to model a set of users, blogs and actions on resources in mongo. Users can perform a no of actions such as 'like', 'star', 'feature' resources of a blog post such as 'blog posts' ,'links', 'images', etc. The model…
Skynet
  • 657
  • 2
  • 9
  • 25