JavacardOS will not accept order any more, please contact our partner Feitian online Store:
https://ftsafe.en.alibaba.com/index.html
https://ftsafe.en.alibaba.com/index.html
Convert a byte array to binary array in Java Card
-
- Posts: 2
- Joined: Wed Jul 29, 2015 5:48 am
- Points :20
- Contact:
Convert a byte array to binary array in Java Card
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.
- 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
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:
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.
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
-
- Posts: 2
- Joined: Wed Jul 29, 2015 5:48 am
- Points :20
- Contact:
Re: Convert a byte array to binary array in Java Card
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?
Who is online
Users browsing this forum: No registered users and 28 guests