How to get a hex value from a decimal integer in Java?
I don't know how to generate a hex "0x83" character from an integer value in Java.
I need a "0x83" value to represent a letter in the Cyrillic alphabet (this letter: ѓ), in or开发者_如何学Cder to send it (the letter) to my printer. When converting 131 (0x83 in decimal) into hex with my converter (below) I get three numbers: 0x31, 0x33 and 0x31.
public String toHex(String arg) {
return String.format("%x", new BigInteger(arg.getBytes()));
}
I need to get 0x83 from this conversion.
If you are trying to convert integer 131 to a hex string, you can try
Integer.toHexString( 131 )
It will return "83" as String.
Here's one example:
String str = Integer.toHexString(131);
System.out.println(str);
String cyrillic = Character.toString((char)0x83)
Have you tried checking out the Java Integer API. Here are a couple of examples:
I don't see a problem, when converting:
System.out.println(Integer.toHexString(131));
returns 83.
Two possibilities, either your printer needs 0x83 as a byte or as string/char
Send as a byte:
int Cyrillic_int = 131;
byte Cyrillic = (byte) Cyrillic_int;
Or send a string representation of 0x83:
int Cyrillic_int = 131;
String Cyrillic = Integer.toHexString(131);
精彩评论