Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
I am confused about the "toBinaryString()" method in Java.?
Here is an example of some simple code:
import static java.lang.Integer.toBinaryString;
public class BitwiseOps {
public static void main(String[] args){
int indicators = 0b1111_0000_0010_1111;
int selectBit3 = 0b000_0011_1111_1110;
// Try the bitwise AND to select the third bit in indicators
System.out.println("indicators = " + toBinaryString(indicators));
System.out.println("selectBit3 =" + toBinaryString(selectBit3));
indicators &= selectBit3;
System.out.println("indicators & selectBit3 = " + toBinaryString(indicators));
// Try the biwise OR to switch the third bit
int indicators = 0b1111_0000_0010_1111;
System.out.println("\nindicators = " + toBinaryString(indicators));
System.out.println("selectBit3 = " + toBinaryString(selectBit3));
// Try the bitwise OR to switch the third bit on
indicators |= selectBit3;
System.out.println("indicators | selectBit3 = " + toBinaryString(selectBit3));
// Now switch the third bit off again
indicators &= -selectBit3;
System.out.println("\nThe third bit in the previous value of integraters has been turned"
+ "off = " + toBinaryString(indicators));
System.out.println("indicators | selectBit3 = " + toBinaryString(selectBit3));
}
}
I always get an error with the original declaration of "int indicators". Netbeans 7.2, which I have used to run this code, says that it does not support this type of declaration. Is there any type of workaround or solution? What am I doing wrong?
2 Answers
- SilentLv 79 years agoFavorite Answer
What you're doing wrong is putting a bunch of random underscores in your binary numbers, for no obvious reason. That is not legal in Java. Remove these underscores and this error will go away.
Also, you've tried to declare two separate local variables with the same name, "indicators". That's going to be another error that will probably only show up once you fix this one.
- hazelzetLv 44 years ago
Hmm, honest adequate. inspite of the undeniable fact that, i visit nonetheless insist on calling it "chivalry" whilst my husband is going out in a snow fall for ice cream and pickles whilst i'm pregnant. he's my knight, what am i able to assert. i'm into courtesy, yet what approximately courtesies that are prolonged because of the fact of gender? whilst a guy bargains with a mouse or a trojan horse that's gotten into the room, and the lady stands around screaming, is he in basic terms being courteous? Why could the reproductive-evolution-based want for a guy to instruct that he will take care of his woman be "lifeless"? Are women human beings going to stop donning lipstick, too?