bitwise

In Programming, do we have a standard as to what 8th bit, 7th bit, first bit or second bit is?

In programming, when we say "the 7th Least Significant Bit", do we have a standard of whether it is bit 7 or bit 6 (if we start from bit 0). Because if we say "the 2nd Least Significant Bit", it sounds like it is bit 1 (counting from bit 0 again), so if 2nd means bit 1, then 7th means bit 6, not bit 7. ...

bitwise OR on strings

How can i do a Bitwise OR on strings? A: 10001 01010 ------ 11011 Why on strings? The Bits can have length of 40-50.Maybe this could be problematic on int ? Any Ideas ? ...

Inherited variables are not reading correctly when using bitwise comparisons

Hey, I have a few classes set up for a game, with XMapObject as the base, and XEntity, XEnviron, and XItem inheriting it. MapObjects have a number of flags, one of them being MAPOBJECT_SOLID. My problem is that XEntity is the only class that correctly detects MAPOBJECT_SOLID. Both Items are Environs are always considered solid by the...

Convert Byte Array to Bit Array?

How would I go about converting a bytearray to a bit array? ...

Bitwise Shifting in C

I've recently decided to undertake an SMS project for sending and receiving SMS though a mobile. The data is sent in PDU format - I am required to change ASCII characters to 7 bit GSM alphabet characters. To do this I've come across several examples, such as http://www.dreamfabric.com/sms/hello.html This example shows Rightmost bits o...

Bitwise Interval Arithmetic

I've recently read an interesting thread on the D newsgroup, which basically asks, Given two (signed) integers a [amin, amax], b [bmin, bmax], what is the tightest interval of a | b? I'm think if interval arithmetics can be applied on general bitwise operators (assuming infinite bits). The bitwise-NOT and shifts are trivial sin...

PHP equivalent javascript >>> shift right with zero fill bitwise operators?

May I know how can I do PHP >>> ? Such operators is not available in PHP, but is available in Javascript. I just managed to discover a function as follow: function zeroFill($a, $b) { $z = hexdec(80000000); if ($z & $a) { $a = ($a>>1); $a &= (~$z); $a |= 0x40000000; ...

Using Powershell's bitwise operators

I'm looking for example of how I would solve the scenario below: Imagine my printer has the following property for "Status" 0 -Offline 2 -Paper Tray Empty 4 -Toner Exhausted 8 -Paper Jam When I query status it returns a value of 12. I can obviously see that this means the printer has the Toner Exhausted and a Paper Jam, but how would...

what's bad about shifting a 32-bit variable 32 bits?

Hey, recently I picked up a copy of Applied Cryptography by Bruce Schneier and it's been a good read. I now understand how several algorithms outlined in the book work, and I'd like to start implementing a few of them in C. One thing that many of the algorithms have in common is dividing an x-bit key, into several smaller y-bit keys. ...

setBit java method using bit shifting and hexadecimal code - question

I am having trouble understanding what is happening in the two lines with the 0xFF7F and the one below it. There is a link here that explains it to some degree. http://www.herongyang.com/java/Bit-String-Set-Bit-to-Byte-Array.html I don't know if 0xFF7F>>posBit) & oldByte) & 0x00FF are supposed to be 3 values 'AND'ed together or how this...

Negative logical shift

In Java, why does -32 >>> -1 = 1 ? It's not specific to just -32. It works for all negative numbers as long as they're not too big. I've found that x >>> -1 = 1 x >>> -2 = 3 x >>> -3 = 7 x >>> -4 = 15 given 0 > x > some large negative number Isn't >>> -1 the same as << 1? But -32 << 1 = -64. I've read up on two's complements, but still ...

Workaround for basic syntax not being parsed.

I want to have a class property that allow for an expression to take place on the right side of the equals sign. All versions of PHP choke on the following code, but it is written in this way to allow for easier extendibility in the future. /* Example SDK Class */ class SDK { /* Runtime Option Flags */ // Strings # 0: Makes...

Setting last N bits in an array

I'm sure this is fairly simple, however I have a major mental block on it, so I need a little help here! I have an array of 5 integers, the array is already filled with some data. I want to set the last N bits of the array to be random noise. [int][int][int][int][int] eg. set last 40 bits [unchanged][unchanged][unchanged][24 bits of ...

Bitwise operation in Java

I have an array of bytes. I want to simulate corrupt data by changing one bit, two, and three bits. How do I do this? ...

A question in java.lang.Integer internal code

Hi folks, While looking in the code of the method: Integer.toHexString I found the following code : public static String toHexString(int i) { return toUnsignedString(i, 4); } private static String toUnsignedString(int i, int shift) { char[] buf = new char[32]; int charPos = 32; int radix = 1 << shift; int mask = ...

Bitwise operators- need pseudocode translation

Hi Could someone translate this statement into pseudo-code (or just plain english)? var c:uint = 0xFF << 24 | r << 16 | g << 8 | b; ...

Efficient bitshifting an array of int?

Hi, To be on the same page, let's assume sizeof(int)=4 and sizeof(long)=8. Given an array of integers, what would be an efficient method to logically bitshift the array to either the left or right? I am contemplating an auxiliary variable such as a long, that will compute the bitshift for the first pair of elements (index 0 and 1) and...

C & PHP: Storing settings in an integer using bitwise operators?

I'm not familiar with bitwise operators, but I have seem them used to store simple settings before. I need to pass several on/off options to a function, and I'd like to use a single integer for this. How can I go about setting and reading these options? ...

How can i multiply and divide with only using bit shifting and adding?

How can i multiply and divide with only using bit shifting and adding? ...

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...