Can anyone please point me to good online tutorials on Bitwise Operations (preferably in Java)? Before anyone write LMGTFY, I've already Googled it but couldn't find one with good examples. |
I am debugging code that has in it expr1 & expr2 where expr1 has a side effect that affects expr2 evaluation result. I suspect that expr2 gets evaluated before expr1, since ... |
I have the methods that do both the multiplication and addition, but I'm just not able to get my head around them. Both of them are from external websites and not ... |
I was reading through the hadoop code and found this line in a partitioner.
(key.hashCode() & Integer.MAX_VALUE) % numReduceTasks
Why are they using the bitwise AND?
|
I am trying to solve a problem that involves basically implementing a logical AND between the input parameter.
The complexity of the problem involves the size of the input parameters. To give ... |
I was looking at the source of Java 1.6's Java.Util.ArrayDeque (a queue implementation) and stumbled on allocateElements() which should size the backing array according to the given number of elements:
private void ...
|
If I wanted to find the absolute value of a 24-bit two's complement integer, would it be best to mask the integer, and if needed negate the original number?
To better illustrate ... |
|
SOLVED
I have an array holding pixel values as Java int (32bit) thus in the form AARRGGBB
I want to manipulate colors indipendently, so my source image will turn more green, or more ... |
I have inherited a library that uses and abuses of bitwise operations. Up to now, I have developed a method that prints the bit representation of the variables that are used ... |
Whats the equivalent of this without ixor ~
if(~(i3 + -1) < -1) { ... }
.
would it be this?
if((i3 + 1) > 0) { ... }
or (doubt this?)
if((i3 + 0) > ...
|
I am using a technology called DDS and in the IDL, it does not support int. So, I figured I would just use short. I don't need that many bits. However, ... |
Consider all combination of length 3 of the following array of integer {1,2,3}.
I would like to traverse all combination of length 3 using the following algorithm from wikipedia
// find ...
|
I'm new to low level operations like this, I'm hoping someone can point out the obvious mistake I must be making here.
//Input value - 00111100
//I want to get the value of ...
|
DDAVE2010 I currently have the display method down, but I am not sure where to go with the main method... Write a program that uses bitwise operations to: (1) generate and ... |
I am using COM4J to integrate my Java application with SDF (Autodesk) compoent toolkit in COM. COM4J generated wrapper interfaces or proxies for this COM object and one of the method signature is @VTID(17) void open( java.lang.String sdfPath, sdf.com.kit.SdfOpenFlags openFlags, boolean useKif); Where the openFlags argument is of type enum. public enum SdfOpenFlags implements ComEnum { sdfOpenRead(1), sdfOpenUpdate(2), sdfCreateNew(4), sdfCreateAlways(8), sdfOpenAlways(16), ... |
Hi, I've coded a pgm like...... public class Mine{ public static void main(String argv[]){ System.out.println(-1); System.out.println((-1 >> 1)); System.out.println((-1 >>> 1)); } } The o/p of the pgm is : -1 -1 2147483647 Could you tell me how is that? I'm a bit confused. My understanding is like, as -1 is an integer (32 bits - 4 bytes) it is represented ... |
17. Bitwise coderanch.com |
Hi guys...this is my first post, so sorry if I post this in the wrong forum.... I have questions about bitwise operators for: 1. What is Left Shift, Right Shift, and Assigned & Unsigned Right Shift ? 2. Is there also Assigned & Unsigned Left Shift ? 3. When do we use them ? And why ? I know the questions ... |
Hi karen, This will answer your question "why did you get -125 instead of 131?". 32bit representation of 124 is 0000 0000 0000 0000 0000 0000 0110 1100 (~n) => 1111 1111 1111 1111 1111 1111 1001 0011 -(a) Since the most significant bit is 1, take 2's complement to find out the number 2's complement of (a) 0000 0000 0000 ... |
|
How would i check (Bitwise) to see if a passed parameter lies within a given range say: between 0-255 OR 0-100 ? is there any way i could create a bit mask based on the boundary values (0 and 255) and somehow mask it over this parameter to give me back a boolean value based on which i can flag the ... |
Java's lack of an unsigned byte bugs me. I used to enjoy using 0..255 in Pascal. I usually do these bitwise operations in ints (taking care to only use the low 8 bits) then convert to byte only if necessary. At least I can see a value like 254 when I want to. When you see -2 I bet the right ... |
NOTE: I'm also asking in this forum: http://forums.sun.com/thread.jspa?threadID=5343597&tstart=0 but do not yet have an answer. I am working with a file that has a header with the size of the file encoded into 4 bytes like: The ID3v2 tag size is encoded with four bytes where the most significant bit (bit 7) is set to zero in every byte, making a ... |
You need to know how to convert binary to decimal numbers. Try it with 1000_0001 in 8 bits two's complement arithmetic first. Remember a 1 in the rightmost bit means 1, then 2, then 4, etc, but in an 8-bit two's complement number, imagine the leftmost bit means -128. This is not how complement arithmetic is defined, but it will give ... |
I am working on a program that requires the use of bitwise manipulators. The problem is that while I can find a lot of articles explaining it lengthy paragraphs, I have yet to find one containing syntax on using it. The setup I need to create is: if (number > 0) { If number is greater than zero, use the >>= ... |
All bitwise shift operators use modulo 32 shifting, except if the left operand is a long, then it uses modulo 64 shifting. Simply said, if you shift your operand by 32 bits, you shift it by 32 % 32 == 0, so you don't shift it at all. Also, on a slightly related note, you shouldn't use the >>> operator on ... |
I wrote a program to find 0's complement and found out that its -1. int bit = 0; System.out.println((~bit)); So I get it that ~ is giving me 2's complement. But what I dont understand how is 0's 2's complement is -1. 00000000 is 0 11111111 is 1's complement 1 00000000 is 2's complement of ... |
I understand that the results are the same in binary, but how can I get Java to handle it properly, I think what youre tryin to get me to see is that its treating the result as an int when it needs to be a long but casting doesnt work since it wont just add in the extra bits. |
Folks, Looking at a piece of code, didn't understand why do we need to do a bitwise & with 0xFF. StringBuffer sb = new StringBuffer("F1"); short hexNum = Short.parseShort(sb.toString(), 16); b[bufIdx] = (byte) (*hexNum & 0xFF*); As we are casting it to byte, the upper byte would be truncated anyways? If I don't get it right, can someone please explain the ... |
30. bitwise forums.oracle.com128 = 0...10000000 123 = 01111011 128 & 123 = 00000000 (0) 64 = 0...01000000 123 = 01111011 64 & 123 = 01000000 (64) 32 = 0...00100000 123 = 01111011 32 & 123 = 00100000 (32) 16 = 0...00010000 123 = 01111011 16 & 123 = 00010000 (16) 8 = 0...00001000 123 = ... |
is there a better way to do it than this: public class Adder { /** The value x+y. */ public static int add(int x, int y) { int i, comb, carry; comb = 0; carry = 0; for (i = 0; i < 32; i += 1) { int shiftx = (((x>>>i)<<31)>>>31)<>>i)<<31)>>>31)< |
|
Thanks, for your examples. However, we use an serializer which does not support enums, so we can't use an enum for the item type. The items have been persisted to a database, which makes it harder to change the type of the item type field. So we will probably stay with an int for the type. |
|
Notice these functions are equivalent to subtracting and adding the appropriate binary number if, and only if, the appropriate bit can be guaranteed set or clear before the start of the targeted by the operation. You can clear the 9th bit by subtracting 0x00000100 from any number that has the 9th bit set. you can set the second bit by adding ... |
You've GOT to be kidding! I posted only ONCE on THIS forum. Javaranch is owned by a different company and does NOT have all the same members that this web forum has. Posting the same question on completely different websites' forums is NOT cross-posting. Cross-posting is posting the same thing in different boards of ONE website's forums. |
I have a set of 63 boolean values I would like to be able to hold inside one Long variable and change the values at will. I've tried a lot of different things, and searched how to preform Bitwise operations but so far I'm having no luck. Any suggestions or links to tutorials would be appreciated. |
|
|
|
HI, actually these are numbers represented in binary form but actulaay i have to deal with decimals only...menas teh algo is same as i told you : 1. trim 2. append 7 bits togther but numbers are to be dealt are +130 and +26 this algo should result in solution +282 I hoep i made it clear |
This might not answer that question, but the JLS says: http://java.sun.com/docs/books/jls/second_edition/html/expressions.doc.html#5121 15.19 Shift Operators If the promoted type of the left-hand operand is int, only the five lowest-order bits of the right-hand operand are used as the shift distance. It is as if the right-hand operand were subjected to a bitwise logical AND operator & (15.22.1) with the mask value 0x1f. ... |