2
Je suis nouveau chez Java. J'apprends.Aide à la conversion de Hex en booléens?
J'essaie de faire ce qui suit: convertir une chaîne hexadécimale en binaire, puis traiter le binaire dans une série de booléens.
public static void getStatus() {
/*
* CHECKTOKEN is a 4 bit hexadecimal
* String Value in FF format.
* It needs to go into binary format
*/
//LINETOKEN.nextToken = 55 so CHECKTOKEN = 55
CHECKTOKEN = LINETOKEN.nextToken();
//convert to Integer (lose any leading 0s)
int binaryToken = Integer.parseInt(CHECKTOKEN,16);
//convert to binary string so 55 becomes 85 becomes 1010101
//should be 01010101
String binaryValue = Integer.toBinaryString(binaryToken);
//Calculate the number of required leading 0's
int leading0s = 8 - binaryValue.length();
//add leading 0s as needed
while (leading0s != 0) {
binaryValue = "0" + binaryValue;
leading0s = leading0s - 1;
}
//so now I have a properly formatted hex to binary
//binaryValue = 01010101
System.out.println("Indicator" + binaryValue);
/*
* how to get the value of the least
* signigicant digit into a boolean
* variable... and the next?
*/
}
Je pense qu'il doit y avoir une meilleure façon d'effectuer l'action. Ce n'est pas élégant. En outre, je suis coincé avec une valeur de chaîne binaire qui doit être traitée en quelque sorte.
Merci. Je vais essayer cela et voir si cela fonctionne. –
[vrai, faux, vrai, faux, vrai, faux, vrai, faux] Merci! –
J'ai simplifié la boucle. –