bitwise

A bit column shift

How can I shift a column in 8x8 area? For example, I have this one 64-bit unsigned integer as follows: #include <boost/cstdint.hpp> int main() { /** In binary: * * 10000000 * 10000000 * 10000000 * 10000000 * 00000010 * 00000010 * 00000010 * 00000010 */ boost::uint64_t...

VB.NET Bit manipulation: how to extract byte from short?

Given this Short (signed): &Hxxxx I want to: Extract the most right &HxxFF as SByte (signed) Extract the left &H7Fxx as Byte (unsigned) Identify if the most left &H8xxx is positive or negative (bool result) ...

Define BIT0, BIT1, BIT2, etc Without #define

Is it possible in C++ to define BIT0, BIT1, BIT2 in another way in C++ without using #define? #define BIT0 0x00000001 #define BIT1 0x00000002 #define BIT2 0x00000004 I then take the same thing and make states out of those bits: #define MOTOR_UP BIT0 #define MOTOR_DOWN BIT1 Note: I am using 32 bits only, not 64 bits. I am also usi...

Turn on leftmost bit of a Short.

Original question changed. I want to bitwise turn off the left most bit of a Short value (&H8000) and leave the other bits as they are. Dim x = BitConverter.GetBytes(Short.MaxValue Or &H8000) Dim z = BitConverter.ToInt16(x, 0) Isn't there any shorter way with bitwise operators? When I do Dim a = Short.MaxValue Or &H8000 I get a c...

bitwise shifiting question

if i have int temp=(1<<31)>>31. How come the temp becomes -1? how do i get around this problem? thanks ...

What is the best way to insert many checkbox inputs into database?

Greetings, I have a form which it has almost 150 checkbox, but they are not in one place, the form is divided into divisions and each division has blocks, the checkboxes are put in these blocks depending on their group where you can find four checkbox in this place and eight in other and 30 in some other and so go on. So I made a two t...

Why use bitwise operators for checking mouse clicks?

I usually write the following to handle a right mouse click. if (e.Button == MouseButtons.Right) { } But, I have seen people do it this way. Can somebody tell me why they do it this way? What's the advantage? if ((e.Button & MouseButtons.Right) == MouseButtons.Right) { } ...

PHP: Read arbitrary number of bits from an arbitrary offset position in binary data

I have some binary data which has a corresponding "map" file which identifies each data point in the binary data by providing a bit offset and length. So, I might have the following mappings: $paths = array ( "path1" => array ("offset" => 224, "size" => 2), "path2" => array ("offset" => 226, "size" => 6), ); In actua...

Bitwise operations in Visual Basic .NET

Hello guys, I'm re-writing some old application in VB.NET to C# and ASP.NET 3.5. Everything is going OK but I have this problem - and, as the database will not be changed, I must find a solution to it. The old app saves the list o desired days (from Sunday to Saturday) in a byte. This is the way it do it: If chkDaily.Checked Then ...

Finding the length of the common prefix in two bytes

Given two bytes, how would I find the length of the common bits at the start of the two bytes. For example: 9 == 00001001 6 == 00000110 Common prefix is 0000, length 4 I'm working in C#, so please stick to C# operations only. Addendum: This particular piece of code will run thousands of times and needs to be very fast. ...

Do bitwise operators (other than shifts) make any mathematical sense in base-10?

According to wiki shifts can be used to calculate powers of 2: A left arithmetic shift by n is equivalent to multiplying by 2^n (provided the value does not overflow), while a right arithmetic shift by n of a two's complement value is equivalent to dividing by 2^n and rounding toward negative infinity. I was always wond...

Is there an elegant way to Invert a Bit value in an SQL insert Statement?

I'm converting some data in SQL Server: INSERT INTO MYTABLE (AllowEdit) (Select PreventEdit from SOURCETABLE) so I need to inverse the bit value from source table. I expected NOT to work, as this is how I would do it in code, but it doesn't. The most elegant way I can think of is: INSERT INTO MYTABLE (AllowEdit) (Select ABS(PreventEd...

php array bitwise

if I have an array of flags and I want to combine them with a bitwise conjunction ie: $foo = array(flag1, flag2); into $bar = flag1 | flag2; Does PHP have any good functions that will do this nicely for me already? ...

Fastest way to read Left-Most bit from unsigned int (C++) ?

Hello, What is the fastest way to read the Left-Most bit from unsigned int ? Thanks, SW ...

[java] Number for each enum item?

Is it possible to define something like this in java? C# code: public enum Character { A = 1, B = 2, C = 4, D = 8 } ... Character ch = /* from user */ if(ch & Character.A) { // some operation... } for example if ch set to Character.B then result of if will be false: ch = 00000000 00000000 00000000 0000001...

rightrotate without bitwise operators

How can I implement the rightrotate (and leftrotate) operations on 32 bit integers without using any bitwise operations? I need this because High Level Shader Language (HLSL) does not allow bitwise oeprations upon numbers, and I need rightrotate for a specific shader I'm trying to implement. ...

64 bit integer math and bitwise operation benchmarks

I'm trying to get a feel for the difference in performance between integer multiplication compared to bitwise operations... I have two potential hashing algorithms acting on 64 bit keys, one which uses a single multiply, single right shift, and single mask, the other which involves several shift and mask operations... but I want to try ...

many to many relationship, bit wise comparison versus linker table

A database table, lets say burger, contains a field that stores bits as an integer value, so it has value of either 1,2,4,8,16 ... A secondary table contains the values 1 = cheese, 2 = tomato, 4=egg, 8 = lettuce, 16 = mayo Bit wise comparison then enables any burger to have any combination of fillings (for the uninitiated a burger with...

Understanding the bitwise AND Operator

Hello, I have been reading about bit operators in Objective-C in Kochan's book, "Programming in Objective-C". I am VERY confused about this part, although I have really understood most everything else presented to me thus far. Here is a quote from the book: The Bitwise AND Operator Bitwise ANDing is frequently used for masking operat...

Subtracting two numbers without using '-' operator

hi, i tried with the following code , but i can't understand why it's giving me wrong answer. i am computing the 2's complement and adding with another no. #include <stdio.h> int add(int a, int b) { while (a) { a = (a & b) << 1; b = a^b; } return b; } int sub(int a, int b) // add a with b's 2's complement. ...