Bartos
Bartos

Reputation: 1037

Convert usb command to byte array

I try to send command to USB device. I have to convert this command : DA AD 02 74 00 BFDB to byte array. I started like this :

private static final byte[] send = new byte[] {
            (byte)0xda,(byte)0xad, // const
            // command

    };

But I don't know what's next. How should I write 02 as a byte, 74 and so on ? Please, help.

Upvotes: 0

Views: 183

Answers (1)

CherryDT
CherryDT

Reputation: 29052

Just continue the same way you did before:

private static final byte[] send = new byte[] {
    (byte)0xDA, (byte)0xAD, (byte)0x02, (byte)0x74,
    (byte)0x00, (byte)0xBF, (byte)0xDB
};

To simplify the syntax, you could also take a look at this answer and then use a string like "DAAD027400BFDB" or even improve the code from that answer to ignore spaces, so you can keep the syntax you had in your question.

Upvotes: 1

Related Questions