bit

Java Iterate Bits in Byte Array

How can i iterate bits in a byte array? ...

Switch on Enum (with Flags attribute) without declaring every possible combination ?

Hello, how do i switch on an enum which have the flags attribute set (or more precisly is used for bit operations) ? I want to be able to hit all cases in a switch that matches the values declared. The problem is that if i have the following enum [Flags()]public enum CheckType { Form = 1, QueryString = 2, TempData = 4, } and i ...

sql query - true => true, false => true or false

Hi, Simple query, possibly impossible but I know there are some clever people out there :) Given a boolean parameter, I wish to define my where clause to either limit a certain column's output - or do nothing. So, given parameter @bit = 1 this would be the result: where column = 1 given parameter @bit = 0 this would be the result: ...

What does this line of code do ?

Hi Confused as to what this code does for (L=0; L < levels; L++, N_half>>=1){ func( y, N_half); } // end: levels for loop In particular this " N_half>>=1 " Thanks ...

Imply bit with constant 1 or 0 in SQL Server

Is it possible to express 1 or 0 as a bit when used as a field value in a select statement? e.g. In this case statement (which is part of a select statement) ICourseBased is of type int. case when FC.CourseId is not null then 1 else 0 end as IsCoursedBased To get it to be a bit type I have to cast both values. case when FC.Course...

Efficient container for bits

I have a bit array that can be very dense in some parts and very sparse in others. The array can get as large as 2**32 bits. I am turning it into a bunch of tuples containing offset and length to make it more efficient to deal with in memory. However, this sometimes is less efficient with things like 10101010100011. Any ideas on a good w...

How to read a single BIT in an Array of Bytes?

The problem is that I have an Array of Byte with 200 Indexes and just want to check that is the Fourth bit of MyArray[75] is Zero(0) or One(1). byte[] MyArray; //with 200 elements //check the fourth BIT of MyArray[75] ...

Cannot group by bit column

In sql server 2005, i in the query builder, i select "Add group by" to automatically add the group by clause to all of the fields i selected. If one or more of those fields are a bit type, i get an error. Why is this? Is casting the column to TINYINT a good fix? ...

How to read and write bits to a byte array

I have a unsigned char buffer, and I'm wondering how I would write and read signed and unsigned bits to this byte buffer. In the Source Engine there is a class named bf_write, which two main methods (used by WriteString, WriteChar, WriteLong, etc.) use two functions named WriteUBitLong and WriteSBitLong. Thanks in advance ...

C - Need to compare `n` lowest bits of an int for equality.

C - Need to compare n lowest bits of an int for equality. I.e. n = 4; xxxx1001 == xxxx1001 (x is don't care) I.e. n = 2; xxxxxx01 == xxxxxx01 Can't think of a nice way to do it without using masks, =). ...

Getting essid via ioctl in ruby

To avoid relying on the wireless tools I want to get the essid directly from the device with ioctl, in C this wouldn't be a problem, but in Ruby it's quite different. The problem is following struct from wireless.h that is used as input/reply of ioctl: struct iw_point { void __user *pointer; /* Pointer to the data (in user space) ...

Archiving from mySQL to Sybase using Powercenter, problem converting varchar to bit

I have to different databases one is mySQL and the other is Sybase IQ. Both have the same table layout and datatypes. One of the fields has a bit datatype. Unfortunately when I pull the mySQL table into Powercenter it makes it converts it to a string(1). Now when I am trying to write the data from Powercenter to the Sybase IQ table u...

C/C++: Force Bit Field Order and Alignment

I read that the order of bit fields within a struct is platform specific. What about if I use different compiler-specific packing options, will this guarantee data is stored in the proper order as they are written? For example: struct Message { unsigned int version : 3; unsigned int type : 1; unsigned int id : 5; unsigned int ...

How could I test if two bit patterns differs in any N bits (position doesn't matter)

Let's say i have this bit field value: 10101001 How would i test if any other value differs in any n bits. Without considering the positions? Example: 10101001 10101011 --> 1 bit different 10101001 10111001 --> 1 bit different 10101001 01101001 --> 2 bits different 10101001 00101011 --> 2 bits different I need to make a lot of t...

How to get the true/false count from a bit field into two separate columns.

I need to create a query that will sum the number of True(1) and False(0) into two separate columns from one bit field. I'm joining 3 tables and need it to be something like: Attribute | Class | Pass | Fail I will be grouping on Attribute and Class. ...

Most significant bit

I haven't dealt with programming against hardware devices in a long while and have forgotten pretty much all the basics. I have a spec of what I should send in a byte and each bit is defined from the most significant bit (bit7) to the least significant (bit 0). How do i build this byte? From MSB to LSB, or vice versa? ...

How are bits stored in memory? (In chunks? Can there be bits of multiple sizes stored toghether?)

I used to think that each memory location contains 8, 16, 32 or 64 bits. So 0101 would be stored in an 8 bit machine as 00000101 (sign extended if it was negative). This was all fine and dandy until I wrote a program in java out of curiosity to find out some more inner workings of this system. The method in question looks like this: p...

Removing Bit fields in a struct

Hey Folks, I have a question. I have a legacy application which used bit fields in a structure. Something like this struct sample { BYTE one: 2; BYTE two : 1; BYTE three: 5; } sampletest; So "three" can have a value of MAX 31 only. Now I have a requirement to increase the MAX value of three. I am planning to r...

How can I print a C double bit-by-bit to see the low-level representation?

I want to learn how the computer represents the double type in bit, but the & and | bit operators can't use double. And memcpy(&d, &src, 8) also doesn't seem to work. Any suggestions? ...

How to Compare Flags in C#? (part 2)

Bit flags are a little difficult to understand :) I know about this and this questions and I do understand the answers and I even followed this article from a good friend of mine. But I still cant figure it out when I need to "evolute" more than the standard... What I'm trying to do is this: if (HttpContext.Current.Session["Debug...