flags

Combine Bitflags

岁酱吖の 提交于 2019-12-22 07:08:43
问题 I have several flags: None = 0 HR = 1 HD = 2, DT = 4, Fl = 8 .. etc I want to create a function where I input a certain flag, lets say : 6. Returned should be HDDT, since 2 | 4 = 6. It can also happen that 3 or more flags are combined or just a single one. e.g. : 7 = 1 | 2 | 4 => HRHDDT. How can I return the concated string depending on the flag value? In my case the enum has many more entries, which would make a simple if statement really uncomfortable, because I would have to cover hundreds

How do I use low-level 8 bit flags as conditionals?

孤者浪人 提交于 2019-12-22 05:36:17
问题 In my keyboard hook, each keypress gets a flag that states if it was injected or not. http://msdn.microsoft.com/en-us/library/ms644967(VS.85).aspx I've distilled a KBDLLHOOKSTRUCT from the lParam. I can access kbd.flags.XXX. I just don't know how to convert this 8bit flag into an if (injected) {... type conditional that I know how to use. If one of you smart computer-science types would help me out I'd really appreciate it. private static IntPtr HookCallback(int nCode, IntPtr wParam, IntPtr

C++ Access to vector from multiple threads

情到浓时终转凉″ 提交于 2019-12-21 17:43:41
问题 In my program I've some threads running. Each thread gets a pointer to some object (in my program - vector). And each thread modifies the vector. And sometimes my program fails with a segm-fault. I thought it occurred because thread A begins doing something with the vector while thread B hasn't finished operating with it? Can it bee true? How am I supposed to fix it? Thread synchronization? Or maybe make a flag VectorIsInUse and set this flag to true while operating with it? 回答1: vector ,

Enum as Flag using, setting and shifting

大兔子大兔子 提交于 2019-12-21 05:48:07
问题 I have two flags: [Flags] enum Flags { A = 1, B = 2 }; I set them like this: Mode = Flags.A | Flags.B; // default value for(int i = 0; i < args.Length; i++) { switch(args[i]) { case "--a": { if ((Mode & Flags.A) == Flags.A && (Mode & Flags.B) == Flags.B) // both, default assume { Mode = Flags.A; // only A } else { Mode |= Flags.A; // append A } break; } case "--b": { if ((Mode & Flags.A) == Flags.A && (Mode & Flags.B) == Mode.B) { Mode = Flags.B; } else { Mode |= Flags.B; } break; } } } and

Git Flag Syntax: why do some flags have -one dash and some have --two?

青春壹個敷衍的年華 提交于 2019-12-21 03:43:12
问题 I am learning Git and have been unable to find any explanation of the flag syntax. I'm not referring to the "bare double dashes" -- which, as we know, indicate that what follows is not an option. I'm referring to various actual flags which sometimes have one dash, and sometimes have two. git log -2 -p -U1 --graph What is the difference between a flag with one dash and two dashes? What does the double dash indicate? For example, the following two flags are identical, (according to this): -q -

Comparing enum flags in C#

左心房为你撑大大i 提交于 2019-12-20 18:28:04
问题 I need to detect if a flag is set within an enum value, which type is marked with the Flag attribute. Usually it is made like that: (value & flag) == flag But since I need to do this by generic (sometimes at runtime I event have only an "Enum" reference. I can not find an easy way to use the & operator. At the moment I make it like this: public static bool IsSet<T>(this T value, T flags) where T : Enum { Type numberType = Enum.GetUnderlyingType(typeof(T)); if (numberType.Equals(typeof(int)))

Android: Intent Flag to destroy activity and start new one

邮差的信 提交于 2019-12-20 18:06:54
问题 So I have a Login Activity This Activity inflates a login.xml layout which has a USER_NAME and PASSWORD EditText Views, when I enter the Username and Password and click the Login Button I start a new Activity. The new Activity has a Logout button which basically just starts the previous Activity like so: Intent loginIntent = new Intent(getActivity(), Login.class); loginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); getActivity().startActivity(loginIntent); According to the Android

How to change the eflags register value in GDB?

落爺英雄遲暮 提交于 2019-12-20 10:23:54
问题 set $eflags does not change eflags value. The old eflags value remains after eg. =>$set $eflag=0x243 [this is just an example input]. Alternatively, is there any way to set individual flags of eflags ? I'm looking for something like: set ZF[zero flag] . Is there a gdb command to do that? 回答1: set $eflags without parenthesis works in GDB 7.7.1 To set an individual flag, use its index. E.g., ZF is the 6th bit, so we can set it with: set $ZF = 6 # define a GDB variable: no effect on registers

Enum flags over 2^32

限于喜欢 提交于 2019-12-20 09:55:54
问题 I am using Enum flags in my application. The Enum can have around 50+ values, so values go up to 2^50. I was just wondering, can I use Math.Pow(2, variable) to calculate these? When I try to do that I get a constant value compile-time error. Is there another way, other than calculating these powers of 2 manually and putting it in? Here's what I am doing: [Flags] internal enum RiskStates : long { None = 0, AL = Convert.ToInt64(Math.Pow(2,0)), AK = 2, AZ = 4, AR = 8, CA = 16, CO = 32, CT = 64,

Enum flags in JavaScript

天大地大妈咪最大 提交于 2019-12-20 08:27:31
问题 I need to emulate enum type in Javascript and approach seems pretty straight forward: var MyEnum = {Left = 1; Right = 2; Top = 4; Bottom = 8} Now, in C# I could combine those values like this: MyEnum left_right = MyEnum.Left | MyEnum.Right and then I can test if enum has certain value: if (left_right & MyEnum.Left == MyEnum.Left) {...} Can I do something like that in Javascript? 回答1: In javascript you should be able to combine them as: var left_right = MyEnum.Left | MyEnum.Right; Then testing