일반 Hex string <-> String object

황제낙엽 2011.11.29 14:53 조회 수 : 818

sitelink1  
sitelink2  
sitelink3 http://1 
sitelink4 http://ko 
sitelink5 http://www.experts-exchange.com/Programm...69882.html 
sitelink6 http://sitelink1 

Question

I want to convert a Hex String to String.
Example input : "41424344"
Example output : "ABCD"


Answer

public static String hexToString(String input, int groupLength) { 

StringBuilder sb = new StringBuilder(input.length() / groupLength); 

  

for (int i = 0; i < input.length() - groupLength + 1; i += groupLength) { 

String hex = input.substring(i, i + groupLength); 

sb.append((char) Integer.parseInt(hex, 16)); 

}

  

return sb.toString(); 

}


Question

String object to Hex string


Answer

public String stringToHex(String st) {

StringBuffer sb = new StringBuffer();

for(int i = 0; i<st.length(); i++){

int ch=(int)st.charAt( i );

String hs = "00"+Integer.toHexString( ch );

sb.append(hs);

return sb.toString();

}


번호 제목 글쓴이 날짜 조회 수
226 JSP 파일에서 getOutputStream() has already been called for this response 에러 황제낙엽 2013.04.24 12212
225 -file.encoding의 역할 (다국어, 한국어) 황제낙엽 2013.04.10 713
224 [The type HttpUtils is deprecated] javax.servlet.http.HttpUtils 황제낙엽 2013.03.20 826
223 com.oreilly.servlet.multipart 를 이용한 파일 업로드 file 황제낙엽 2013.03.19 765
222 String to InputSource 황제낙엽 2012.12.03 789
221 Class.getResource() vs. ClassLoader.getResource()/getResources() 황제낙엽 2012.06.24 652
220 Jar파일에 포함된 리소스 접근하는 방법(How to read a resource from a JAR file ) file 황제낙엽 2012.06.24 841
219 Java에서 URL 다루기 file 황제낙엽 2012.06.24 597
218 HttpServletResponse.setContentType(java.lang.String type) 과 MIME 타입 황제낙엽 2012.04.20 733
217 code, codebase 속성과 applet object 동적 생성 file 황제낙엽 2012.04.17 835
216 한글 파일명 깨짐으로 살펴본 다국어 처리 문제 (UTF-8) 황제낙엽 2012.03.22 10714
215 BufferedReader.readLine() hangs 황제낙엽 2012.02.23 986
214 OS 쉘 명령어(shell script) 실행하기 [ProcessBuilder, Runtime.getRuntime().exec()] 황제낙엽 2012.02.22 1261
213 PreProcess 실행 (전처리기 만들기) file 황제낙엽 2012.01.04 808
212 javax.script와 타입변환 황제낙엽 2012.01.03 870
211 Scripting within Java 황제낙엽 2012.01.03 772
» Hex string <-> String object 황제낙엽 2011.11.29 818
209 An alternative to the deep copy technique file 황제낙엽 2011.07.27 763
208 <jsp:include>, include지시자 file 황제낙엽 2011.07.24 673
207 <jsp:include> 액션태그 황제낙엽 2011.07.24 631