[JAVA] hex to byte[], byte[] to hex

자바에서 헥사 스트링을 바이트 값으로 변환하는 소스

// hex to byte[]
public static byte[] hexToByteArray(String hex) {
    if (hex == null || hex.length() == 0) {
        return null;
    }

    byte[] ba = new byte[hex.length() / 2];
    for (int i = 0; i < ba.length; i++) {
        ba[i] = (byte) Integer.parseInt(hex.substring(2 * i, 2 * i + 2), 16);
    }
    return ba;
}

// byte[] to hex
public static String byteArrayToHex(byte[] ba) {
    if (ba == null || ba.length == 0) {
        return null;
    }

    StringBuffer sb = new StringBuffer(ba.length * 2);
    String hexNumber;
    for (int x = 0; x < ba.length; x++) {
        hexNumber = "0" + Integer.toHexString(0xff & ba[x]);

        sb.append(hexNumber.substring(hexNumber.length() - 2));
    }
    return sb.toString();
} 

'programming > java' 카테고리의 다른 글

Java SE의 정규 표현식(정규식, Regular Expressions)  (0) 2009.09.15
필수 자바 라이브러리  (0) 2009.04.07
Singleton Templet  (0) 2008.09.23
XPath 간단예제들  (0) 2008.09.18
XOM 시작하기(Creating XML Documents)  (0) 2008.09.18

모질라. Firefox 3.0.2 배포

파이어 폭스 3.0.1 버전이 나왔습니다. 다운로드는

http://www.mozilla.com/en-US/products/download.html?product=firefox-3.0.2&os=win&lang=ko

또는 메뉴에서 [Help] - [Check for Update] 를 누르시면 됩니다.
변경사항은 아래와 같습니다...

# Fixed several security issues.
# Fixed several stability issues.
# Official releases for Sinhala and Slovene are now available.
# Beta releases for Bengali, Galician, Hindi, Icelandic, Kannada, Marathi, Telugu, and Thai are available for testing.
# Fixed a number of minor issues with the layout of certain web pages.
# Fixed several theme issues that affected right-to-left locales.
# Fixed issue that caused some users with customized toolbars to have their Back and Forward buttons go missing (bug 426026)
# Add new Extended Validation (EV) roots to Firefox 3.0.2.
# On certain IDN sites, the password manager would not fill in username and password details properly.
# Fixed several hangs and crashes that occurred when using screen readers.
# Fixed Mac-specific issues:
    * Keyboard shortcuts would stop working in some cases.
    * Japanese, Korean, Chinese and Indic characters can not be entered (using IME) into text fields in Flash objects (bug 357670)
    * Firefox 3.0.1 could not be used when the user profile is stored on an AFP directory (bug 417037)

Singleton Templet

싱글톤 코딩시 참조.

public class ${Name} {
    private static ${Name} instance;

    public static ${Name} getInstance() {
        if (instance == null) {
            synchronized (${Name}.class) {
                // double-check idiom
                if (instance == null) {
                    instance = new ${Name}();
                }
            }
        }
        return instance;
    }

    private ${Name}() {
    }
}

'programming > java' 카테고리의 다른 글

필수 자바 라이브러리  (0) 2009.04.07
[JAVA] hex to byte[], byte[] to hex  (0) 2008.10.07
XPath 간단예제들  (0) 2008.09.18
XOM 시작하기(Creating XML Documents)  (0) 2008.09.18
XOM 소개  (0) 2008.09.18