0

I'm trying to copy two Byte arrays into another. The problem is that the first element of the result Byte is strange, I get 0xFFFFFF80 instead of 0x80. the code I'm using is:

    this.IC_SUBMIT_APDU = new byte[13];
    byte[] prefix = {
        (byte) 0x80,
        (byte) 0x20,
        (byte) 0x07,
        (byte) 0x00,
        (byte) 0x08
    };
    System.arraycopy(prefix , 0, this.IC_SUBMIT_APDU, 0, prefix.length);

    for(int i=0; i<this.IC_SUBMIT_APDU.length ; i++)
        System.out.println("" + Integer.toHexString(this.IC_SUBMIT_APDU[i]));

when I give it this argument:

{
    (byte) 0x41,
    (byte) 0x43,
    (byte) 0x4F,
    (byte) 0x53,
    (byte) 0x54,
    (byte) 0x45,
    (byte) 0x53,
    (byte) 0x54
}

it produces the following result:

ffffff80
20
7
0
8
0
0
0
0
0
0
0
0

WHy do I get that 0xFFFFFF80 ? am I not supposed to get 0x80 ??

1
  • You must read it from right to left two numbers at a time, so you have 80 FF FF FF. As said mattm in his answer, the FFFFFF part comes from somewhere else or is filler. Commented May 15, 2017 at 14:06

3 Answers 3

3

0xFFFFFF80 is more than one byte. The 0xFFFFFF portion is probably from a different print statement that you have not shown.

Sign up to request clarification or add additional context in comments.

1 Comment

I have no print statement before this one.
2

Nothing to do with System.arrayCopy.

In fact, System.out.println(Integer.toHexString((byte) 0x80)); will also print ffffff80.

You have an arithmetic overflow when casting hex 0x80 as byte, since its decimal value is 128, i.e. 1 more than byte's capacity (Byte.MAX_VALUE, or 127) and overflows to -128.

Note that in turn, Integer.toHexString returns the representation of an unsigned integer, hence the additional overflow.

Comments

0

your are copying correctly the only 5 elements present in ic_submit_apdu_prefix ...

hint: 0x80 with 8 bits is -128 (2 complement)

0xffffff80 = -128

0x20 = 32

7

0

8

0

the rest is zero. (default initial primitive value)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.