Convert a byte array to binary array in Java Card
Posted: Sun Oct 25, 2015 4:19 am
How can I convert a byte array to binary array in Java Card ,such as 10101010?
JavaCardOS - JavaCardForum
https://javacardos.com/javacardforum/
https://javacardos.com/javacardforum/viewtopic.php?f=15&t=204
Code: Select all
for (short i = 0; i < length; ++i) {
byte oneByte = input[(short)(iOffset + i)];
for (short j = 0; j < (short) 8; ++j) {
output[(short)(oOffset2++)] = ((oneByte & 0x80) != 0) ? true : false;
oneByte <<= 1;
}
}
UNKNwYSHSA wrote:What't the relationship of the code and the post topic? You make a mistake?
Why you have this requirement?
You can implement this function like this:Code: Select all
for (short i = 0; i < length; ++i) {
byte oneByte = input[(short)(iOffset + i)];
for (short j = 0; j < (short) 8; ++j) {
output[(short)(oOffset2++)] = ((oneByte & 0x80) != 0) ? true : false;
oneByte <<= 1;
}
}
Notice: use boolean to save memory space.
You can get the value when you use it if you use byte array as boolean flags. One-time conversion is not necessary.