블로그 이미지
blueye

카테고리

내블로그 (52)
창작활동 (10)
저장활동 (16)
관심 (0)
Total
Today
Yesterday
출처 : http://funtrip.tistory.com/
_________________________________________________________________________________________________________________
자바에서는 C언어와 같이 unsigned 타입의 데이터형이 존재하지 않는다. C언어로 코딩되어 있는 모듈과 통신시 자바측에서 이러한 unsigned 타입을 처리해야한다.

다음은 이러한 unsigned 타입의 데이터형을 보정하는 클래스 소스이다. 문제가 있거나 더 나은 방안이 있으면 공유 바람.

  1. public class UnsignedUtil {   
  2.     public static int byte2uchar(byte b) {   
  3.         return (int) (b & 0xff);   
  4.     }   
  5.   
  6.     public static byte uchar2byte(int c) {   
  7.         return (byte) (c & 0xff);   
  8.     }   
  9.   
  10.     public static int short2ushort(short s) {   
  11.         return (int) (s & 0xffff);   
  12.     }   
  13.   
  14.     public static short ushort2short(int s) {   
  15.         return (short) (s & 0xffff);   
  16.     }   
  17.   
  18.     public static long int2uint(int i) {   
  19.         return (long) (i & 0xffffffffL);   
  20.     }   
  21.   
  22.     public static int uint2int(long i) {   
  23.         return (int) (i & 0xffffffffL);   
  24.     }   
  25. }  

 

Posted by blueye
, |

최근에 달린 댓글

최근에 받은 트랙백

글 보관함