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
0
votes
0 answers

Parsing String to a Short Mask

Good day. I'm working with the Tinkerforge Java API to do some programming. I ran into a Problem, where i've to create a short Mask looking something like: "0b11011011" I'm using the following code to parse my config into the Mask Required: I'm…
0
votes
1 answer

Apply boolean mask to Scala array

I'm trying to use an array of booleans to choose particular elements in another array. For example: val arr = Seq("A", "B", "C") val mask = Seq(true,false,true) and I'd like the output to be a new array: val arr_new = Seq("A","C") Is there a way…
Feynman27
  • 3,049
  • 6
  • 30
  • 39
0
votes
0 answers

Hamming Weight of Int64

I'd like to ask how the BitMask looks like when I need to apply the hamming weight algoritm on an Int64 to count the set bits. For an Int32 it looks like this: public int HammingWeight(int value) { value = value - ((value >> 1) &…
yq8
  • 145
  • 1
  • 10
0
votes
2 answers

Mapping a bitfield to another bitfield in C#

I have two bitfields, one of 8 bits and one of 4 bits. [Flags] public enum Bits1 { A = 1, B = 2, C = 4, D = 8, E = 16, F = 32, G = 64, H = 128 } [Flags] public enum Bits2 { I = 1, J = 2, K = 4, L = 8 } I need to map the…
GameKyuubi
  • 681
  • 1
  • 10
  • 25
0
votes
0 answers

What work Bitmask at C#

I am trying to deal with a bit mask: Mask |= 1 << MapID; anybody can explain how it works? Thanks for help guys
0
votes
1 answer

Check if a bitmask value is contained in the sum of many bitmask values

I have the following specification of bitmask values: // Structure of Database: // SC_NAME, flag // // flag 1 - SC cannot be removed by death. // 2 - SC cannot be saved. // 4 - SC cannot be reset by dispell. // 8 - SC…
Latheesan
  • 23,247
  • 32
  • 107
  • 201
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
1 answer

Is It Possible to Use Hashcodes as a Bitmask to Efficiently Store/Track Collection Membership?

Currently I have a solution where I keep track of objects I am interested in by getting their hashcode via Object.GetHashCode and then storing them in a HashSet. However, I have also been learning about bitmasks and bitwise operations and I am…
Mike-E
  • 2,477
  • 3
  • 22
  • 34
0
votes
2 answers

Why does a shifted integer mask with a tilde casted to a long return zero? (Java, bit shift)

I am trying to create a mask to view specific bits on a long in Java. I tried the following: long mask = ~ (0xffffffff << 32); If I print this on the console it will return 0 but I am expecting 4294967295 since my result should look like…
thiloilg
  • 1,733
  • 2
  • 18
  • 23
0
votes
1 answer

Placing a new value into a section of a big Python bitarray

Using Python 2.7 and bitarray 0.8.1 to hold several sequenced register values (registers can be from 16 to 512 Byte long). I want to set a value to a specific part of this bitarray? For example: from bitarray import bitarray BYTE = [False,…
Gilbert
  • 29
  • 4
0
votes
2 answers

SpriteKit Category Bitmask Not Working Correctly

In my xcode project I am trying to create a function that gets called when a SKShapeNode hits the world border(edge of screen) that I have created. The SKShapeNode hits the edge of the screen and rolls to the right due to the gravity but when the…
Charles
  • 31
  • 3
0
votes
1 answer

Calculating subsets of an array within a given range?

Given an array of n numbers, how can we calculate the subsets of that array (0 based indexed) in a given range i.e starting from ith index to jth index. I tried using bitmasking but couldn't figure out how to solve this because of the range. For…
ashwani
  • 690
  • 3
  • 16
0
votes
1 answer

Bitmask operations on slices of Python bytearrays

Say I have a bytearray like the following : mask = bytearray([0b0001, 0b0100, 0b0111]), where each bit represents a certain flag. I would like to add a flag to slices of the mask array like so : mask[0:2] = mask[0:2] | 0b1000 but I get a TypeError…
user5283407
  • 143
  • 8
0
votes
2 answers

combining two different information in binary code

I have Dictionary where string represents the key of record, and I have two other pieces of information about the record that I need to maintain for each record in the dictionary, which are the category of the record and its redundancy…
0
votes
1 answer

Don't understand why result is one

I had to create a function that can be given an int with up to 32 bits. It is supposed to return 1 if an odd bit is 1 and 0 otherwise. I understand that if it does not match the mask it returns zero, but I don't understand why it returns one if it…
Stan
  • 13
  • 2