출처 : http://funtrip.tistory.com/
_________________________________________________________________________________________________________________
자바에서는 C언어와 같이 unsigned 타입의 데이터형이 존재하지 않는다. C언어로 코딩되어 있는 모듈과 통신시 자바측에서 이러한 unsigned 타입을 처리해야한다.
다음은 이러한 unsigned 타입의 데이터형을 보정하는 클래스 소스이다. 문제가 있거나 더 나은 방안이 있으면 공유 바람.
_________________________________________________________________________________________________________________
자바에서는 C언어와 같이 unsigned 타입의 데이터형이 존재하지 않는다. C언어로 코딩되어 있는 모듈과 통신시 자바측에서 이러한 unsigned 타입을 처리해야한다.
다음은 이러한 unsigned 타입의 데이터형을 보정하는 클래스 소스이다. 문제가 있거나 더 나은 방안이 있으면 공유 바람.
- public class UnsignedUtil {
- public static int byte2uchar(byte b) {
- return (int) (b & 0xff);
- }
- public static byte uchar2byte(int c) {
- return (byte) (c & 0xff);
- }
- public static int short2ushort(short s) {
- return (int) (s & 0xffff);
- }
- public static short ushort2short(int s) {
- return (short) (s & 0xffff);
- }
- public static long int2uint(int i) {
- return (long) (i & 0xffffffffL);
- }
- public static int uint2int(long i) {
- return (int) (i & 0xffffffffL);
- }
- }
public class UnsignedUtil {
public static int byte2uchar(byte b) {
return (int) (b & 0xff);
}
public static byte uchar2byte(int c) {
return (byte) (c & 0xff);
}
public static int short2ushort(short s) {
return (int) (s & 0xffff);
}
public static short ushort2short(int s) {
return (short) (s & 0xffff);
}
public static long int2uint(int i) {
return (long) (i & 0xffffffffL);
}
public static int uint2int(long i) {
return (int) (i & 0xffffffffL);
}
}