Java Bitwise Operators
sir_creamy_
Inactive Imported Users Posts: 298
Hey guys,
How would I flip a single bit using Java bitwise operators?
So if I have -4 represented as a twos complement integer (i.e., 1111 1111 1111 1111 1111 1111 1111 1100) and I want to change a specific bit, how would I do that?
The operators work on all bits of an int, correct?
EDIT: My apologies for posting this in the wrong forum. Thought I was in "Off-topic"
How would I flip a single bit using Java bitwise operators?
So if I have -4 represented as a twos complement integer (i.e., 1111 1111 1111 1111 1111 1111 1111 1100) and I want to change a specific bit, how would I do that?
The operators work on all bits of an int, correct?
EDIT: My apologies for posting this in the wrong forum. Thought I was in "Off-topic"
Bachelor of Computer Science
[Forum moderators are my friends]
[Forum moderators are my friends]
Comments
-
sir_creamy_ Inactive Imported Users Posts: 298I should probably add that I won't know what the bit pattern will be ahead of time. So it's not merely a matter of XOR-ing a predefined bit pattern with another bit pattern to achieve the result.Bachelor of Computer Science
[Forum moderators are my friends] -
JDMurray Admin Posts: 13,093 AdminHave a look at the get, set, and clear methods in this Java class: http://www.krugle.org/kse/files/svn/svn.apache.org/db/derby/code/trunk/java/testing/org/apache/derbyTesting/unitTests/util/BitUtil.java#2
And TE's Java certs forum is the place for these questions.