bitmask

bitmask question?

北城余情 提交于 2020-01-11 15:36:48
问题 I have the follow: public static final int LIMIT_ONE = 1; public static final int TRADEABLE = (1 << 1); public static final int SELLABLE = (1 << 2); public static final int STORABLE = (1 << 3); public static final int STORABLE_IN_WH = (1 << 4); public static final int STORABLE_IN_LEGION_WH = (1 << 5); public static final int BREAKABLE = (1 << 6); public static final int SOUL_BOUND = (1 << 7); public static final int UNK9 = (1 << 8); public static final int UNK10 = (1 << 9); public static

bitmask question?

泄露秘密 提交于 2020-01-11 15:35:12
问题 I have the follow: public static final int LIMIT_ONE = 1; public static final int TRADEABLE = (1 << 1); public static final int SELLABLE = (1 << 2); public static final int STORABLE = (1 << 3); public static final int STORABLE_IN_WH = (1 << 4); public static final int STORABLE_IN_LEGION_WH = (1 << 5); public static final int BREAKABLE = (1 << 6); public static final int SOUL_BOUND = (1 << 7); public static final int UNK9 = (1 << 8); public static final int UNK10 = (1 << 9); public static

Fastest way to produce a mask with n ones starting at position i

杀马特。学长 韩版系。学妹 提交于 2020-01-09 05:18:06
问题 What is the fastest way (in terms of cpu cycles on common modern architecture), to produce a mask with len bits set to 1 starting at position pos : template <class UIntType> constexpr T make_mask(std::size_t pos, std::size_t len) { // Body of the function } // Call of the function auto mask = make_mask<uint32_t>(4, 10); // mask = 00000000 00000000 00111111 11110000 // (in binary with MSB on the left and LSB on the right) Plus, is there any compiler intrinsics or BMI function that can help?

Generic single flag enumeration for bitmask enums

℡╲_俬逩灬. 提交于 2020-01-05 04:09:28
问题 I'm working on a codebase with several bit flags enums which look something like this public enum BitMask { None = 0, OptionA = 1 << 0, OptionB = 1 << 1, OptionAandB = OptionA | OptionB, All = ~0 } I can iterate over all enum values using this public IEnumerable<T> EnumValues<T>() { return Enum.GetValues(typeof(T)).Cast<T>(); } I'm looking for a generic way to iterate over single flag values only, in this case, OptionA and OptionB . Not None , OptionAandB , All . I can cast to long and detect

c# - Get Specific Bit and Get first 14 bits of a ushort value

微笑、不失礼 提交于 2020-01-03 06:34:11
问题 After reading all of the questions and answers on bit shifting/masking, I simply cannot wrap my head around it. I'm just not understanding how it works on a fundamental level. I've been able to achieve various techniques by using BitArray and BitConverter instead, but I really would like to understand bit shifting/masking better. The specific need I have is to do the following: I have a ushort: 0x810E (33038) Using bit shifting/masking, I'd like to know how to: Get the 16th bit Result: 1 Get

Is there any difference between integer and bit(n) data types for a bitmask?

老子叫甜甜 提交于 2020-01-01 07:50:07
问题 I am working with a table in a PostgreSQL database that has several boolean columns that determine some state (e.g. published , visible , etc.). I want to make a single status column that will store all these values as well as possible new ones in a form of a bitmask. Is there any difference between integer and bit(n) in this case? This is going to be a rather big table, because it stores objects that users create via a web-interface. So I think I will have to use (partial) indexes for this

Storing multiple values via bitmask in c#

折月煮酒 提交于 2019-12-30 05:15:12
问题 I'm trying to store four independent 5-bit values (0-31) inside a 32-bit int via bit mask but am having trouble getting the values correct to set and get the individual values from the masked int used for storage. Can anyone help me with this? Edit: Sorry for the external link - here's some JavaScript demonstrating what I'm trying to achieve (but in bitmasks instead of decimal algebra): var s = 0; var v = [31, 6, 23, 31]; //save values s = v[0] + (v[1] * 32) + (v[2] * 1024) + (v[3] * 32768);

TYPO3: Reading the values of a TCA 'type' => 'check' (bitmask)

你离开我真会死。 提交于 2019-12-25 01:45:36
问题 I need to show a selection of days in an event in the frontend: in my TCA I set the field like this: 'days' => [ 'exclude' => true, 'label' => 'choose weekdays', 'config' => [ 'type' => 'check', 'eval' => 'required,unique', 'items' => [ ['monday',''], ['thuesday',''], ['wednesday',''], ['thursday',''], ['friday',''], ['saturday',''], ['sunday',''], ], 'cols' => 'inline', ], ], That stores an integer in the db, but now I have to display the selected days in a fluid template in the frontend.

Checking specific bits of a bitmask

一笑奈何 提交于 2019-12-24 10:23:03
问题 I am working with Bitmasks in python . As far as I know, these are arrays of integers that when they are unpacked into binary format they tell you which of the 32 bits are set (=1) for a given element in the array. I would like to know the fastest way to check whether 4 specific bits are set or not for any element of an array. I do not care about the rest. I have tried the following solution but it is not fast enough for my purpose: def detect(bitmask, check=(18,22,23,24), bits=32): boolmask

How to take bit number 3 from 8 bits

久未见 提交于 2019-12-23 18:23:18
问题 I have this in hex: 08 Which is this in binary: 0000 1000 (bit positions: 7,6,5,4,3,2,1,0) Now I would like to make a bitmask in python, so I have bit position 3. Here in example 1 or better (the one in ""): 0000 "1"000 What shall I do to have only this bit? Thanks 回答1: Shift right by the bit index to have that bit in the 0th position, then AND with 1 to isolate it. val = 0b01001000 # note the extra `1` to prove this works pos = 3 bit = (val >> pos) & 1 print(bit) outputs 1 回答2: you could