Questions tagged [bit-masks]

bitmasks are data used for bitwise operations.

54 questions
1
vote
3 answers

Analysing &, && and | for this code?

I want to illustrate the difference with this code for(i = 32; i > 0; i--) { if(a&1 != 0) //bit mask total += b; a = a >> 1; b = b << 1; } In the code & is used to "mask" a bit and the result would have been completely different…
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424
1
vote
2 answers

Writing a function: short GetBits(short data, int p, int n)

I am writing a function short getBits(short data, int p, int n) I have tried: public static short getBits(short data, int p, int n) { short bitmask = (short) ((~0 << (16 -n)) >>> p); short returnVal = (short) ((bitmask & data) >>> (16 -…
powerj1984
  • 2,216
  • 1
  • 22
  • 34
0
votes
4 answers

How to check a returned bit mask value?

I am calling this function from C#: GetKeyboardStatus() Looking at the documentation it says that it returns a bit mask value. The goal of my code is to determine if the device has a physical keyboard with alphanumeric characters. I have…
still_dreaming_1
  • 8,661
  • 6
  • 39
  • 56
0
votes
0 answers

Quantize normalized vector for network communication

I am wondering if is possible to send Vector3(float x, float y, float z) in some kind of shorter data type, because right now I am sending three floats (3*4 bytes). I am talking about normalized vector, which can hold only range from -1f to +1f for…
0
votes
1 answer

I need an infinite bit-mask in C++

Skippable Context: I have a simulation loop (using fixed update but variable rendering pattern), which instantiates entities of classes that are generated on the fly according to user-input and/or file configurations from a database of millions of…
0
votes
1 answer

Masks (macros of bits)

So I'm about to finish my course in university in C programming. I want to get better at bit operations (such as creating masks) so I'll go to it: #define BIT_I_SET(TYPE,I) ((TYPE)(1) << (I)) #define SET_BIT(NUM,I,TYPE) \ NUM |=…
AmitBL
  • 89
  • 4
  • 12
0
votes
2 answers

Finding a mask value with higher and lower position of the register

A 32 bit register i.e. status_reg has 1 field (field_1 <0:31>). To set and clear this register I am trying to get mask value of this register. So in general to get mask value the formula is: mask = ((~(~0 << (hbit-lbit+1))) << lbit) In this hbit is…
ziga
  • 109
  • 10
0
votes
1 answer

Trouble with bit masks in SpriteKit SWIFT

In my game I have circles that have different colors. They should only collide with boundaries that are not of their color. To do that I at first assign the normal circle a category bit mask. struct CollisionCategoryBitmask { static let…
Lenny1357
  • 748
  • 1
  • 13
  • 21
0
votes
1 answer

Bit Masking in C#, converting from enum to byte []

I have a question regarding bit masking which I am completely new to. In the application there is currently means of taking a byte[] of addresses and from them determining which alarms (bools) are true of false. I am looking to reverse this. I would…
Colm Clarke
  • 480
  • 1
  • 7
  • 23
0
votes
1 answer

st_mode of a symlink has weird value

I'm stat()'ing this symlink (on Kubuntu GNU/Linux 16.04), and am getting the weird value of 0100600 octal (33152 decimal). If I bitwise-and it with S_IFMT (which is 0170000 octal), I get 0600 octal. What does that mean? stat.h lists the following…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
0
votes
0 answers

How to represent in bistmasks the type of bounce of AWS SES

I'm writing a Symfony's Bundle to manage AWS SNS notifications sent by AWS SES. I'm representing a Bounce object and for the moment I'm using constants: /** * A Bounce Entity. * * @see…
Aerendir
  • 6,152
  • 9
  • 55
  • 108
0
votes
1 answer

ulong, bitmask and bit shift in PHP from C#

Ok so my problem is that I've to "process" a big integer from an endpoint response. This is a hash and I've to do some bit mask and bit shifts in order to view this data (it's a version: major, minor, build, etc) in a human readable way. In C# I've…
fratili
  • 31
  • 5
0
votes
0 answers

Bit masking with decimal offset: Faster algorithm?

I've a sum build of 0 up to 3 specific decimal numbers that can build 8 different sums: 100 --- 100 --- 100 --- 100 --- 200 200 --- --- 200 200 --- --- + 400 + 400 + 400…
Sebastian Barth
  • 4,079
  • 7
  • 40
  • 59
0
votes
3 answers

Why does the BitConverter return Bytes and how can I get the bits then?

As input I get an int (well, actually a string I should convert to an int). This int should be converted to bits. For each bit position that has a 1, I should get the position. In my database, I want all records that have an int value field that has…
Boris Callens
  • 90,659
  • 85
  • 207
  • 305
0
votes
4 answers

Why does bit shifting a negative number doesn't work?

Here is my code: long x1 = -123; long y1 = -312; long x2 = -111; long y2 = -112; long packed = x1 | y1 << 15 | x2 << 30 | y2 << 45; Debug.log("x1:" + ((packed) & 0b111111111111111)); Debug.log("y1:" + ((packed >> 15) &…
Gintas_
  • 4,940
  • 12
  • 44
  • 87