Skip to content

Instantly share code, notes, and snippets.

@kunst1080
Last active December 24, 2015 09:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kunst1080/6780360 to your computer and use it in GitHub Desktop.
Save kunst1080/6780360 to your computer and use it in GitHub Desktop.
ShiftJISの文字コード値を16進数表記で得る
import java.io.UnsupportedEncodingException;
public class Char2SjisHexString {
// Test
public static void main(String args[]){
String str = "月陽炎DVD";
for (char c : str.toCharArray()) {
System.out.println(Character.toString(c) + ":" + char2SjisHexString(c));
}
}
// Main
private static String char2SjisHexString(char c) {
try {
String s = Character.toString(c);
byte[] buf = s.getBytes("Windows-31J");
String result = "0x";
for (byte b : buf) {
result += String.format("%02x", b);
}
return result;
} catch (UnsupportedEncodingException e) {
return "エラー";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment