tagged [bit-manipulation]

Fastest way to get last significant bit position in a ulong (C#)?

Fastest way to get last significant bit position in a ulong (C#)? What is the fastest(or at least very fast) way to get first set(1) bit position from least significant bit (LSB) to the most significa...

C# .NET: if ((e.State & ListViewItemStates.Selected) != 0) <- What does it mean?

C# .NET: if ((e.State & ListViewItemStates.Selected) != 0)

19 May at 14:33

What are bitwise shift (bit-shift) operators and how do they work?

What are bitwise shift (bit-shift) operators and how do they work? I've been attempting to learn C in my spare time, and other languages (C#, Java, etc.) have the same concept (and often the same oper...

What does a bitwise shift (left or right) do and what is it used for?

What does a bitwise shift (left or right) do and what is it used for? I've seen the operators `>>` and `

Bitwise operation and usage

Bitwise operation and usage Consider this code: ``` x = 1 # 0001 x

Writing 'bits' to C++ file streams

Writing 'bits' to C++ file streams How can I write 'one bit' into a file stream or file structure each time? Is it possible to write to a queue and then flush it? Is it possible with C# or Java? This ...

22 Aug at 11:8

what is the correct way to process 4 bits inside an octet in python

what is the correct way to process 4 bits inside an octet in python I'm writing an application to parse certain network packets. A packet field contains the protocol version number in an octet, so tha...

19 Oct at 08:18

Is there a way to perform a circular bit shift in C#?

Is there a way to perform a circular bit shift in C#? I know that the following is true ``` int i = 17; //binary 10001 int j = i

6 Oct at 15:15

Bitwise subtraction

Bitwise subtraction Given the enum: then If I don't know if foo contains `c`, previously I have been writing the following Is there a way to do this without checking for the existance of `foo.c` in `e...

23 Sep at 08:44

Most common C# bitwise operations on enums

Most common C# bitwise operations on enums For the life of me, I can't remember how to set, delete, toggle or test a bit in a bitfield. Either I'm unsure or I mix them up because I rarely need these. ...

28 Oct at 18:33

C# int to byte[]

C# int to byte[] I need to convert an `int` to a `byte[]` one way of doing it is to use `BitConverter.GetBytes()`. But im unsure if that matches the following specification: > An XDR signed integer is...

20 Feb at 13:53

Set a specific bit in an int

Set a specific bit in an int I need to mask certain string values read from a database by setting a specific bit in an int value for each possible database value. For example, if the database returns ...

16 Jun at 19:14

How do I test if a bitwise enum contains any values from another bitwise enum in C#?

How do I test if a bitwise enum contains any values from another bitwise enum in C#? For instance. I have the following enum So I set mystuff to then I set hisstuff to How do I now test if these overl...

29 Jan at 21:3

Fastest way to convert int to 4 bytes in C#

Fastest way to convert int to 4 bytes in C# What is a fastest way to convert int to 4 bytes in C# ? Fastest as in execution time not development time. My own solution is this code: Right now I see tha...

27 Nov at 11:32

How do I check, if bitmask contains bit?

How do I check, if bitmask contains bit? I don't quite understand this whole bitmask concept. Let's say I have a mask: I undestand that this is how I would combine `8` and `524288`, and get `524296`. ...

23 Jan at 12:40

Is shifting bits faster than multiplying and dividing in Java? .NET?

Is shifting bits faster than multiplying and dividing in Java? .NET? Shifting bits left and right is apparently faster than multiplication and division operations on most, maybe even all, CPUs if you ...

When are bitwise operations appropriate

When are bitwise operations appropriate I am aware of the basic premise of what bitwise operation are (although would appreciate a "for dummies" explanation); however I am unaware of when it is approp...

Binary Shift Differences between VB.NET and C#

Binary Shift Differences between VB.NET and C# I just found an interesting problem between translating some data: VB.NET: `CByte(4)

How does BitConverter.ToInt32 work?

How does BitConverter.ToInt32 work? Here is a method - ``` using System; class Program { static void Main(string[] args) { // // Create an array of four bytes. // ... Then convert it i...

3 Nov at 12:51

How to check if a particular bit is set in C#

How to check if a particular bit is set in C# In C#, I have a 32 bit value which I am storing in an int. I need to see if a particular bit is set. The bit I need is `0x00010000`. I came up with this s...

10 Aug at 00:25

Why bit shifting?

Why bit shifting? I was recently looking at a config file that was saving some cryptic values. I happened to have the source available, so I took a look at what it was doing, and it was saving a bunch...

22 Sep at 18:39

C# Bitwise-or operator used on a sign-extended operand; consider casting to a smaller unsigned type first

C# Bitwise-or operator used on a sign-extended operand; consider casting to a smaller unsigned type first I know these warnings are probably pointless.. But anyway I could get rid of them? I got 7 of ...

C# EF Linq bitwise question

C# EF Linq bitwise question Ok for example, I am using bitwise like such: Monday = 1, Tuesday = 2, Wednesday = 4, Thursday = 8 etc... I am using an Entity Framework class of Business. I am using a cla...

Fast way of finding most and least significant bit set in a 64-bit integer

Fast way of finding most and least significant bit set in a 64-bit integer There are a lot of questions about this on StackOverflow. . However I cannot find an answer that: - - Faster than: Or even I'...

11 Apr at 01:25

What is the fastest/most efficient way to find the highest set bit (msb) in an integer in C?

What is the fastest/most efficient way to find the highest set bit (msb) in an integer in C? If I have some integer `n`, and I want to know the position of the most significant bit (that is, if the le...