JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html

Convert a byte array to binary array in Java Card

JavaCard Applet Development Related Questions and Answers.
user143816329648988
Posts: 2
Joined: Wed Jul 29, 2015 5:48 am
Points :20
Contact:

Convert a byte array to binary array in Java Card

Post by user143816329648988 » Sun Oct 25, 2015 4:19 am

How can I convert a byte array to binary array in Java Card ,such as 10101010?
Last edited by user143816329648988 on Sun Oct 25, 2015 9:56 pm, edited 1 time in total.

User avatar
UNKNwYSHSA
Posts: 630
Joined: Thu May 21, 2015 4:05 am
Points :3053
Contact:

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

Post by UNKNwYSHSA » Sun Oct 25, 2015 6:05 am

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.
sense and simplicity

user143816329648988
Posts: 2
Joined: Wed Jul 29, 2015 5:48 am
Points :20
Contact:

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

Post by user143816329648988 » Sun Oct 25, 2015 9:56 pm

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?

Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 34 guests

JavaCard OS : Disclaimer