bit-manipulation

Java Precedence - Casting and Bitwise Operators

生来就可爱ヽ(ⅴ<●) 提交于 2020-05-23 19:48:31
问题 I am having a hard time understanding some code that shows an example how a double in Java could be transformed into a byte[] and vice versa. Here is the code being used to transform a double into a byte[]: public static byte [] doubleToByteArray (double numDouble) { byte [] arrayByte = new byte [8]; long numLong; // Takes the double and sticks it into a long, without changing it numLong = Double.doubleToRawLongBits(numDouble); // Then we need to isolate each byte // The casting of byte (byte

Java Precedence - Casting and Bitwise Operators

人盡茶涼 提交于 2020-05-23 19:46:41
问题 I am having a hard time understanding some code that shows an example how a double in Java could be transformed into a byte[] and vice versa. Here is the code being used to transform a double into a byte[]: public static byte [] doubleToByteArray (double numDouble) { byte [] arrayByte = new byte [8]; long numLong; // Takes the double and sticks it into a long, without changing it numLong = Double.doubleToRawLongBits(numDouble); // Then we need to isolate each byte // The casting of byte (byte

mirror bits of a 32 bit word

烂漫一生 提交于 2020-05-23 06:07:51
问题 How would you do that in C? (Example: 10110001 becomes 10001101 if we had to mirror 8 bits). Are there any instructions on certain processors that would simplify this task? 回答1: It's actually called "bit reversal", and is commonly done in FFT scrambling. The O(log N) way is (for up to 32 bits): uint32_t reverse(uint32_t x, int bits) { x = ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1); // Swap _<>_ x = ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2); // Swap __<>__ x = ((x & 0x0F0F0F0F)

mirror bits of a 32 bit word

守給你的承諾、 提交于 2020-05-23 06:07:06
问题 How would you do that in C? (Example: 10110001 becomes 10001101 if we had to mirror 8 bits). Are there any instructions on certain processors that would simplify this task? 回答1: It's actually called "bit reversal", and is commonly done in FFT scrambling. The O(log N) way is (for up to 32 bits): uint32_t reverse(uint32_t x, int bits) { x = ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1); // Swap _<>_ x = ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2); // Swap __<>__ x = ((x & 0x0F0F0F0F)

mirror bits of a 32 bit word

不想你离开。 提交于 2020-05-23 06:07:02
问题 How would you do that in C? (Example: 10110001 becomes 10001101 if we had to mirror 8 bits). Are there any instructions on certain processors that would simplify this task? 回答1: It's actually called "bit reversal", and is commonly done in FFT scrambling. The O(log N) way is (for up to 32 bits): uint32_t reverse(uint32_t x, int bits) { x = ((x & 0x55555555) << 1) | ((x & 0xAAAAAAAA) >> 1); // Swap _<>_ x = ((x & 0x33333333) << 2) | ((x & 0xCCCCCCCC) >> 2); // Swap __<>__ x = ((x & 0x0F0F0F0F)

How Does The Bitwise & (AND) Work In Java?

痞子三分冷 提交于 2020-05-19 08:33:02
问题 I was reading through some code examples and came across a & on Oracle's website on their Bitwise and Bit Shift Operators page. In my opinion it didn't do too well of a job explaining the bitwise & . I understand that it does a operation directly to the bit, but I am just not sure what kind of operation, and I am wondering what that operation is. Here is a sample program I got off of Oracle's website: http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase

How Does The Bitwise & (AND) Work In Java?

前提是你 提交于 2020-05-19 08:30:13
问题 I was reading through some code examples and came across a & on Oracle's website on their Bitwise and Bit Shift Operators page. In my opinion it didn't do too well of a job explaining the bitwise & . I understand that it does a operation directly to the bit, but I am just not sure what kind of operation, and I am wondering what that operation is. Here is a sample program I got off of Oracle's website: http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase

Bitwise operation in C language (0x80, 0xFF, << )

一个人想着一个人 提交于 2020-05-15 10:45:33
问题 I have a problem understanding this code. What I know is that we have passed a code into a assembler that has converted code into "byte code". Now I have a Virtual machine that is supposed to read this code. This function is supposed to read the first byte code instruction. I don't understand what is happening in this code. I guess we are trying to read this byte code but don't understand how it is done. static int32_t bytecode_to_int32(const uint8_t *bytecode, size_t size) { int32_t result;

Bitwise operation in C language (0x80, 0xFF, << )

╄→尐↘猪︶ㄣ 提交于 2020-05-15 10:45:12
问题 I have a problem understanding this code. What I know is that we have passed a code into a assembler that has converted code into "byte code". Now I have a Virtual machine that is supposed to read this code. This function is supposed to read the first byte code instruction. I don't understand what is happening in this code. I guess we are trying to read this byte code but don't understand how it is done. static int32_t bytecode_to_int32(const uint8_t *bytecode, size_t size) { int32_t result;

Bitwise AND (&) between negative and positive numbers?

拥有回忆 提交于 2020-05-13 17:52:27
问题 I've been learning about adding two numbers using bit manipulation and I am having issues understanding how it is done in Python for negative numbers. For example, if I am trying to & the following: -0b1111010 (-122) & 0b11011110 (222) shouldn't it be: 0b1111010 & 0b11011110 ------------ 0b01011010 since only a combination of 1's results in 1's? Right now python gives 0b10000110 I couldn't find any resources specifically when a negative number is added to a positive number using python. 回答1: