Last active
December 24, 2015 09:58
-
-
Save kunst1080/6780360 to your computer and use it in GitHub Desktop.
ShiftJISの文字コード値を16進数表記で得る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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