## C/C++ Compressing Integer to Short and Decompressing to Integer [closed]

I’m trying to find a way to send a value through the network that is 16bit in length (short), whilst its original value is determined by 32bit in length (Integer). The idea is to save traffic size …

## What is the Javascript’s highest value that can be safely used in a bitmask?

Let’s say I want to create a bitmask in Javascript. I would toggle a bit on like this: mask |= (1 << bit); clear a bit like this: mask &= ~(1 << bit); and check if a bit is set like ...

## Writing a bit reader in JAVA (32-bit little-endian most-to-least-significant bit packing)

No matter how I toss and turn the bytes & bits, I just cannot get this to work. I understand endianess quite ok, and MSB (most significant bit) on some degree. But I’m not able to put the two …

## Is there a bit-wise trick for checking the divisibility of a number by 2 or 3?

I am looking for a bit-wise test equivalent to (num%2) == 0 || (num%3) == 0. I can replace num%2 with num&1, but I’m still stuck with num%3 and with the logical-or. This expression is also …

## Bit level manipulation in Java / reinterpreted_cast<> in Java?

Is there anyway to treat as a float an int’s value (and back)? Like this: int myInt = 1729; float myFloat = intToFloatPreservingBitPattern(myInt); int otherInt = floatToIntPreservingBitPattern(…

## Performance wise, how fast are Bitwise Operators vs. Normal Modulus?

Does using bitwise operations in normal flow or conditional statements like for, if, and so on increase overall performance and would it be better to use them where possible? For example: if(i++ &…

## Java: right shift on negative number

I am very confused on right shift operation on negative number, here is the code. int n = -15; System.out.println(Integer.toBinaryString(n)); int mask = n >> 31; System.out.println(Integer….

## Right shift with zeros at the beginning

I’m trying to do a kind of left shift that would add zeros at the beginning instead of ones. For example, if I left shift 0xff, I get this: 0xff << 3 = 11111000 However, if I right shift it, I ...