bit

Convert bit vector (array of booleans) to an integer, and integer to bit vector, in Java.

What's the best way to unstub the following functions? // Convert a bit-vector to an integer. int bitvec2int(boolean[] b) { [CODE HERE] } // Convert an integer x to an n-element bit-vector. boolean[] int2bitvec(int x, int n) { [CODE HERE] } Or is there a better way to do that sort of thing than passing boolean arrays around...

Using a bitwise AND on more than two bits.

Hi, I am pretty new to bitwise operators. Let's say I have 3 variables a, b and c, with these values in binary: a = 0001 b = 0011 c = 1011 Now, I want to perform a bitwise AND like this: a AND b AND c -------- d = 0001 d &= a &= b &= c doesn't work (as I expected), but how can I do this? Thanks ...

Merging Bit, Enum and Set fields in MySql

I know up to eight Bit fields are merged into one byte to save space, but what if I have a couple of Bit fields and an Enum or a Set field? Are they internally merged too? I'm asking because I'm going to have a lot of rows in my table and I want to avoid overhead as much as possible. ...

how is data stored at bit level according to "Endianness" ?

I read about Endianness and understood squat... so I wrote this main() { int k = 0xA5B9BF9F; BYTE *b = (BYTE*)&k; //value at *b is 9f b++; //value at *b is BF b++; //value at *b is B9 b++; //value at *b is A5 } k was equal to A5 B9 BF 9F and (byte)pointer "walk" o/p was 9F BF b9 A5 so I get it byte...

Integer Types in file formats

Hi, I am currently trying to learn some more in depth stuff of file formats. I have a spec for a 3D file format (U3D in this case) and I want to try to implement that. Nothing serious, just for the learning effect. My problem starts very early with the types, that need to be defined. I have to define different integers (8Bit, 16bit, 3...

Convert a byte into a boolean array of length 4 in Java

I need to convert a byte into an array of 4 booleans in Java. How might I go about this? ...

Perl pack/unpack/shift

I've been having this problem in Perl for a few days now, and after scouring countless man pages, perldocs and googling too many search terms, hopefully someone here can help me out. I am given two strings which represent hex values, i.e. "FFFF", not the Perl hex number 0xFFFF. Given two of these strings, I wish to convert them to bina...

Using bitset in place of using hand written bit manipulation code?

Is there any performance loss/gain using bitset in place where hand written? How to build the following using a bitset at runtime make all the bits between 2 and 5 as zero i.e., 11110011. ...

What is the binary representation of a boolean value in c#

I know that a boolean value is 1 byte (8 bits long) But I would like to know is what is its binary representation. e.g. decimal => binary 4 => 100 (0000 0100) 8 => 1000 (0000 1000) bool value => ??? ...

Select a nullable bit with a default value

I need to select a nullable bit column in a view, but use a default value of FALSE whenever the value is NULL. (For other reasons, I can't add the default value on the source table itself.) Here is what I am doing. CAST ( CASE WHEN bit_column IS NULL THEN 0 ELSE bit_column END AS BIT ) AS bit_column, ... I ha...

How to store bits to a huge char array for file input/output

HI, all. Here are the things I want to do : I want to store lots of informations to a block by bits, and save it into a file. In order to keep my file not so big, I only want to use a small number of bits to save specified information instead of a int. For example, I want to store Day, Hour, Minute to a file. I only want 5 bit(day)...

Sum of the bits in Java

Hi again, sorry Friends i did a mistake. I have did this mistake again. am really very sorry. this is the Issue. I have a time range like int Starttime = 2 which mean(02:00) int enttime = 8 which mean(08:00) i want time in sum of bits, example 00:00 1 01:00 2 02:00 4 ----- 03:00 8 R 04:00 16...

BIT(1) vs ENUM('unknown', 'male', 'female') in MySQL

In performance terms, what will be faster, use a BIT(1) NULL (null = unknown, 0 = male, 1 = female) or ENUM('unknown', 'male', 'female') NOT NULL DEFAULT 'unknown' in MySQL MyISAM? Or this is considered micro-optimization? [EDIT] I think I'm going to use ENUM('male', 'female') DEFAULT NULL ...

MySQL: Example of where to use the BIT Data Type

If I understand correctly, the pre MySQL 5.0.3 interpretation of the BIT data type meant it could be used as a series of flags? If this is the case I can see practical uses for it in MySQL but imagine it would not have been as efficient as using SET. Even if the above is not the case, I have great difficulty in understanding how the cur...

MySQL BIT vs SET

Does anyone know where in the MySQL literature the reference is made to merging BIT fields? I am having a hard time locating any documentation that distinguishes SET from BIT. ...

Is a logical right shift by a power of 2 faster?

Hi there, I would like to know if performing a logical right shift is faster when shifting by a power of 2. I am using C++. For example, is myUnsigned >> 4 any faster than myUnsigned >> 3 I appreciate that everyone's first response will be to tell me that one shouldn't worry about tiny little things like this, it's using correct a...

Bit Array in C++

When working with Project Euler problems I often need large (> 10**7) bit array's. My normal approach is one of: bool* sieve = new bool[N]; bool sieve[N]; When N = 1,000,000 my program uses 1 MegaByte (8 * 1,000,000 bits). Is there a more efficient way to use store bit arrays than bool in c++? ...

Why does each location in memory contain 8 bits?

Somebody has confirmed there are 8 bits in every location/address in memory. Can I know why? is it related to the memory chip architecture? Or is it because of 32bit CPU. Is this 8 bits true for another OS such as FreeBSD, Mac, Linux? Is there any relation the amount of bits in every location to the count of address line in memory? Is ...

Counting bits in a int - why does this code work?

I was trying to learn more about bits, and I came across this example. How does this code work to count the bits? (My C is very rusty, by the way). unsigned int v; // count the number of bits set in v unsigned int c; // c accumulates the total bits set in v for (c = 0; v; v >>= 1) { c += v & 1; } ...

Rotating bits of any integer in C

Pass a integer 2 to this function and then return a integer which is 4 x = 2; x = rotateInt('L', x, 1); (left shift the bits by 1) Example: 00000010 -> rotate left by 1 -> 00000100 but if I pass this: x = rotateInt('R', x, 3); it will return 64, 01000000 Here is the code, can someone correct the error... thanks int rotateInt...