bitwise-operators

What are bitwise operators?

I'm someone who writes code just for fun and hasn't really delved into it in either an academic or professional setting, so stuff like this really escapes me. I was reading an article about JavaScript, which apparently supports bitwise operations. I keep seeing this mentioned in places and I've tried reading about to figure out what exac...

Weird bit-shift behavior

I'm in the process of porting some ANSI C++ code to C#... and this is killing me right now. Both tests have value = 6844268. Test code: value >> 12 value & 0x00000FFF C++ returns 18273 and 29497, whereas C# returns 1670 and 3948. I've tried every possible combination of types in C# (int, uint, long, ulong, Int64...), but no go :( O...

How use bit/bit-operator to control object state?

I want to create light object data-package to pass between client and server applications. It is a so simple task, that I can control with only 1 byte, so each bit in a byte will have a different meaning, Using only the bit 0 = False 1 = True Itens I need now: 1 - Loaded from database 2 - Persisted 3 - Changed 4 - Marked to Dele...

How to use a bitwise operator to pass multiple Integer values into a function for Java?

In application frameworks I keep seeing frameworks that allow you to pass in multiple Int values (generally used in place of an enum) into a function. For example: public class Example { public class Values { public static final int ONE = 0x7f020000; public static final int TWO = 0x7f020001; public sta...

Some random C questions (ascii magic and bitwise operators)

Hi, I am trying to learn C programming, and I was studying some source codes and there are some things I didn't understand, especially regarding Bitwise Operators. I read some sites on this, and I kinda got an idea on what they do, but when I went back to look at this codes, I could not understand why and how where they used. My first ...

A clear, layman's explanation of the difference between | and || in c# ?

Ok, so I've read about this a number of times, but I'm yet to hear a clear, easy to understand (and memorable) way to learn the difference between: if (x | y) and if (x || y) ..within the context of C#. Can anyone please help me learn this basic truth, and how C# specifically, treats them differently (because they seem to do the ...

Bit operations on Enum

I'm having some problems with the following: I want to get the first visible AND frozen column of a column collection. I think this will do it: DataGridViewColumnCollection dgv = myDataGridView.Columns; dgv.GetFirstColumn( DataGridViewElementStates.Visible | DataGridViewElementStates.Frozen); Is it also possible to make a bi...

How to use the & operator in C#? Is the the translation of the code correct?

Hello, the line "if(arg2 & 1)" in C++(arg2 is DWORD) is equal to "if(arg2 & 1==0)" in C#(arg2 is Uint32),right? I am trying to translate a function from C++ to C#,but I get an error: Operator '&' cannot be applied to operands of type 'uint' and 'bool' I'd be also thankful if you could see further in the whole function for any other ...

Shift operators in PL/SQL

Whether there is an alternative of shift operators in PL/SQL? There is bitand function, but it accepts only *binary_integer*-type arguments. What should i do if i need check up lower/higher bit of really long number (probably set in the line)? In C there are << and >> operators. How I can realise them in PL/SQL? ...

What is the inverse of bitwise AND in C#?

I need to do an inverse calculation, which consists bitwise AND operation,how do I do it? I tried exclusive OR, but it didn't help. int i = 254 & 2; Console.Write("254 & 2 ={0}", i + "\n"); Console.Write("{0} ^ 2 ={1}",i, (i ^ 2) + "\n"); Doesn't work. How do I do that calculation? ...

How does the bitwise complement (~) operator work?

Why is it that ~2 is -3? ...

C# bitwise rotate left and rotate right

Hi I am looking for C# equivalent (.Net 2) of _rotl and _rotr from c++. Any ideas ? Thanks, ...

Convert Delphi Bitwise Operation to Cobol

How can this code be converted to COBOL? Result := GetSysColor(Color and $000000FF) The value types are DWORD, I guess it is a bitwise operation. ...

C: what is the result of I and ^ operation on char?

There is a piece of code: int p(char *a, char*b) { while (*a | *b) { if (*a ^ *b) //... } } and I don't really know what it's doing. Edit: I understand what the | and ^ operators do, I just don't know what they'll do with char values. ...

Bitwise Not Operator (~ in C) with regards to little endian and big endian

This is in relation to a homework assignment but this is not the homework assignment. I'm having difficultly understanding if there is a difference on how the bitwise not (~ in C) would affected signed int and unsigned int when compiled on a big endian machine vs. a little endian machine. Are the bytes really "backwards" and if so do...

AS3 bitwise shift 0?

I came across this in some AS 3.0 code: (duration >> 0) Where duration is a Number. I think I know what a bitwise right shift does, but what's the point of shifting 0 bits? This happens a few times in the code, I'd like to understand what it does. ...

Opposite of Bitwise OR operation.

I compute c = a 'OR' b // bitwise OR operation here Now given only values of c and b how can I compute the original value of a? ...

Looking for a bitwise operator.

Hi. I have a list of objects of the same class. The order of the list is not important. What i want to do, is to (using bitwise operations) determine whether i should set some field with an incremental value or not. But the trick is that i want need this operation to return false (must not set field) only for the first element. for (Ob...

Optimizing bitwise filtering in SQL

I am implementing a bitwise filter using SQL, and I want to see if the following optimization is always valid in all cases, and I'm not sure how to prove it. My goal is to limit the number of rows that get compared. Standard filter pseudo-sql: IF (A & B = A) // SHOW VALUE The question is, will it work to add this? : IF (A = B) OR (A...

How can I write 'n <<= 1' (Python) in PHP?

I have the Python expression n <<= 1 How do you express this in PHP? ...