Is there a straightforward way to extracting the exponent from a power of 2 using bitwise operations only?
EDIT: Although the question was originally about bitwise operations, the thread is a good read also if you are wondering "What's the fastest way to find X given Y = 2**X in Python?"
I am currently trying to optimize a routine (Rab...
I need to compare a query bit sequence with a database of up to a million bit sequences. All bit sequences are 100 bits long. I need the lookup to be as fast as possible. Are there any packages out there for fast determination of the similarity between two bit sequences? --Edit-- The bit sequences are position sensitive.
I have seen a p...
Hi all,
I want to find 9's complement of number but failed.
I tried it with the methods of 1's and 2's complements but no effect.
What is common method to find out the N's complement of a number?
...
Hello,
I'm very confused about behaviour of PHP's left shift function. I'm using it on two different machines (dev and hosting), and they are giving me different answers. I've tracked it down to this calculation:
(-3941404251) << 5;
On one machine I'm getting the answer -1570884448; on the other, I get 0. On both systems, PHP_INT_MAX ...
how to add 2 numbers without using + and bitwise operators?
...
Hi,
I have heard somewhere that using XOR is not reversible (they spoke about encryption) but I do not understand how it was meant? AFAIK even with OR operation you cannot find out which of the two bits was 1. Please, could anyone who knows how it was meant explain it to me?
Thank you
...
Alright, so I have 4 integers I want to wrap in a long.
The 4 integers all contains 3 values, positioned in the first 2 bytes:
+--------+--------+
|xxpppppp|hdcsrrrr|
+--------+--------+
{pppppp} represents one value, {hdcs} represents the second and {rrrr} the last.
I want to pack 4 of these integers, in a long. I've tried the f...
The Problem:
I want to return all of the rows from the Primary Data table together with the Highest Priority Exception based on the currently assigned Priority in an Exception table.
I have created a simplified example of my data set-up below (with creation scripts) so hopefully you can help with what should be a fairly quick T-SQL pr...
This work nicely
Public Const test As ULong = 1 << 30
This doesn't work nicely
Public Const test As ULong = 1 << 31
It create this error:
Constant expression not representable in type 'ULong'
Anyone know how to make it work?
This does work:
Public Const test As Long = 1 << 31
But I have to use ULong
...
Are there any efficient bitwise operations I can do to get the number of set bits that an integer ends with? For example 1110 = 10112 would be two trailing 1 bits. 810 = 10002 would be 0 trailing 1 bits.
Is there a better algorithm for this than a linear search? I'm implementing a randomized skip list and using random numbers to determi...
Okay, I am working on a card playing program, and I am storing card values as hexadecimal digits. Here is the array:
public int[] originalCards = new int[54]
{
0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0...
Shhow me a very simple one line example in C# to check if a given bit is set in given byte
function signature should be like
bool IsBitSet(Byte b,byte nPos)
{
return .....;
}
...
Hi
The question seems pretty well formulated
I have a virtual machine which implements only AND, XOR, SHL and SHR, yet I have to do a "OR 0x01" operation.
...
I have the following code:
tmp_data = simulated_data[index_data];
unsigned char *dem_content_buff;
dem_content_buff = new unsigned char [dem_content_buff_size];
int tmp_data;
unsigned long long tmp_64_data;
if (!(strcmp(dems[i].GetValType(), "s32")))
{
dem_content_buff[BytFldPos] = tmp_data;
dem_content_buff[BytFldPos + 1] = tm...
Hello,
I have the following problems:
First: I am trying to do a 32-spaces bitwise left shift on a large number, and for some reason the number is always returned as-is. For example:
echo(516103988<<32); // echoes 516103988
Because shifting the bits to the left one space is the equivalent of multiplying by 2, i tried multiplying the...
For my university process I'm simulating a process called random sequential adsorption.
One of the things I have to do involves randomly depositing squares (which cannot overlap) onto a lattice until there is no more room left, repeating the process several times in order to find the average 'jamming' coverage %.
Basically I'm performi...
Hi all
I am trying to do bit reversal in a byte. I use the code below
static int BitReversal(int n)
{
int u0 = 0x55555555; // 01010101010101010101010101010101
int u1 = 0x33333333; // 00110011001100110011001100110011
int u2 = 0x0F0F0F0F; // 00001111000011110000111100001111
int u3 = 0x00FF00FF; // 00000000111111110000000...
I actually just have a rather small question, but I have had the HARDEST time finding information about it.
For the application I am programming for, there will be a 3-axis joystick being connected via USB to a Windows XP computer, and it is being handled by directx. That information will then be sent elsewhere to an embedded controlle...
I want to create a very large array on which I write '0's and '1's. I'm trying to simulate a physical process called random sequential adsorption, where units of length 2, dimers, are deposited onto an n-dimensional lattice at a random location, without overlapping each other. The process stops when there is no more room left on the latt...
What are the best methods to "Clear the 6th bit" of an integer?
And, is your solution platform independent? (32 or 64 bit integer, etc). If not, can you give a solution that is platform independent?
Update: we don't know whether that bit is set or unset when it was given... also, any language is ok... i know of a solution that is p...