Page 1 of 1

Convert a byte array to binary array in Java Card

Posted: Sun Oct 25, 2015 4:19 am
by user143816329648988
How can I convert a byte array to binary array in Java Card ,such as 10101010?

Re: Convert a byte array to binary array in Java Card

Posted: Sun Oct 25, 2015 6:05 am
by UNKNwYSHSA
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.

Re: Convert a byte array to binary array in Java Card

Posted: Sun Oct 25, 2015 9:56 pm
by user143816329648988
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.


Sorry, it's my fault. I have updated my question.

But it seems that your code doesn't solve my question. I want to convert a byte array to binary array. Is there any method?