brian
brian

Reputation: 6922

How to convert byte to the same string in Java

I try to convert byte to the same string. Such as below:

byte b = (byte)0xAA;

Then, convert byte b to the same string as below:

String s = "AA";

How can I do it?

Upvotes: 0

Views: 141

Answers (3)

kosa
kosa

Reputation: 66657

Byte.toString(b) will print String representation of String for specified byte 'b'

Upvotes: 0

Jason Kuang
Jason Kuang

Reputation: 261

Try this:

byte b = (byte)0xAB; String s = String.format("%x", b);

Upvotes: 4

Bernard
Bernard

Reputation: 7961

Have you tried using the Byte class? It has toString() methods you can use.

Upvotes: 0

Related Questions