在Java里面如何表示无符号的整数?如C里面的byte, char, WORD等。(100分)

  • 主题发起人 主题发起人 Hank
  • 开始时间 开始时间
H

Hank

Unregistered / Unconfirmed
GUEST, unregistred user!
请教:在Java里面如何表示无符号的整数?如C里面的byte, char, WORD等。
我需要将一个LZH算法的C源码转换为Java的,可在数据类型的映射上出现了问题:
Java中除了char类型可以表示16bits的无符号整数外,象C中的byte类型在Java中
没法表示。不知道众位高手由没有什么好的方法?或者有LZH的Java源码更好!
先谢谢了!
 
short int long byte char 都有
 
TO NoSwing: 都有什么?
我就是在把下面的C程序转换为Java程序的时候碰到问题的。谁能够把它转换为Java程序?
// Compress.h: interface for the CCompress class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_COMPRESS_H__20E933F4_C65C_11D1_9249_0080C88672DB__INCLUDED_)
#define AFX_COMPRESS_H__20E933F4_C65C_11D1_9249_0080C88672DB__INCLUDED_
#if _MSC_VER >= 1000
#pragma once
#endif // _MSC_VER >= 1000
#define _LZH_N 4096
#define _LZH_F 60
#define _LZH_THRESHOLD 2
#define _LZH_NIL _LZH_N
#define _LZH_N_CHAR (256 - _LZH_THRESHOLD + _LZH_F)
#define _LZH_T (_LZH_N_CHAR * 2 - 1)
#define _LZH_R (_LZH_T - 1)
#define _LZH_MAX_FREQ 0x8000
class CCompress
{
public:
char * m_pcIn;
long m_lIn;
char * m_pcOut;
long m_lOut;
BOOL Encode();
BOOL Decode();
CCompress();
CCompress(int nLength);
virtual ~CCompress();
private:
long m_lInCount;
long m_lOutCount;
BYTE m_pbyBuffer[_LZH_N + _LZH_F - 1];
short m_nMatchPos;
short m_nMatchLen;
short m_pnLeftSon[_LZH_N + 1];
short m_pnRightSon[_LZH_N + 257];
short m_pnDad[_LZH_N + 1];
WORD m_pwFreq[_LZH_T + 1];
short m_pnParent[_LZH_T + _LZH_N_CHAR];
short m_pnSon[_LZH_T];
WORD m_wGetBuf;
BYTE m_byGetLen;
WORD m_wPutBuf;
BYTE m_byPutLen;
WORD m_wCode;
WORD m_wLen;
void StartHuff();
short DecodeChar();
short DecodePosition();
short GetBit();
short GetByte();
void Update(short);
void ReConstruct();
void InitTree();
void InsertNode(short);
void DeleteNode(short);
void EncodeChar(WORD);
void EncodePosition(WORD);
void EncodeEnd();
void PutCode(short, WORD);
};
#endif // !defined(AFX_COMPRESS_H__20E933F4_C65C_11D1_9249_0080C88672DB__INCLUDED_)
//=============================================================================
// Compress.cpp: implementation of the CCompress class.
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "Compress.h"
#include <windowsx.h>
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif
unsigned char p_len[64] = {
0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
};
unsigned char p_code[64] = {
0x00, 0x20, 0x30, 0x40, 0x50, 0x58, 0x60, 0x68,
0x70, 0x78, 0x80, 0x88, 0x90, 0x94, 0x98, 0x9C,
0xA0, 0xA4, 0xA8, 0xAC, 0xB0, 0xB4, 0xB8, 0xBC,
0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA, 0xCC, 0xCE,
0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE,
0xE0, 0xE2, 0xE4, 0xE6, 0xE8, 0xEA, 0xEC, 0xEE,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
};
unsigned char d_code[256] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A,
0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B,
0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D,
0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F,
0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11,
0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13,
0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15,
0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17,
0x18, 0x18, 0x19, 0x19, 0x1A, 0x1A, 0x1B, 0x1B,
0x1C, 0x1C, 0x1D, 0x1D, 0x1E, 0x1E, 0x1F, 0x1F,
0x20, 0x20, 0x21, 0x21, 0x22, 0x22, 0x23, 0x23,
0x24, 0x24, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27,
0x28, 0x28, 0x29, 0x29, 0x2A, 0x2A, 0x2B, 0x2B,
0x2C, 0x2C, 0x2D, 0x2D, 0x2E, 0x2E, 0x2F, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
};
unsigned char d_len[256] = {
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
};
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCompress::CCompress(int nLength)
{
m_wGetBuf = 0;
m_byGetLen = 0;
m_wPutBuf = 0;
m_byPutLen = 0;
m_pcIn = (char *)GlobalAllocPtr(GHND, nLength);
m_lIn = 0;
m_pcOut = (char *)GlobalAllocPtr(GHND, nLength);
m_lOut = 0;
}
CCompress::CCompress()
{
m_wGetBuf = 0;
m_byGetLen = 0;
m_wPutBuf = 0;
m_byPutLen = 0;
m_pcIn = (char *)GlobalAllocPtr(GHND, 128l*1024l);
m_lIn = 0;
m_pcOut = (char *)GlobalAllocPtr(GHND, 128l*1024l);
m_lOut = 0;
}
CCompress::~CCompress()
{
if (m_pcIn)
GlobalFreePtr(m_pcIn);
if (m_pcOut)
GlobalFreePtr(m_pcOut);//hwg???
}
BOOL CCompress::Decode()
{
long lSize;
memmove(&amp;lSize, m_pcIn, 4);
if (lSize == 0)
return FALSE;
m_lInCount = 4;
m_lOutCount = 0;
m_wGetBuf = 0;
m_byGetLen = 0;

StartHuff();
short nR = _LZH_N - _LZH_F;
memset(m_pbyBuffer, ' ', nR);
for (m_lOutCount = 0;
m_lOutCount < lSize;
)
{
short nC = DecodeChar();
if (nC < 256)
{
m_pcOut[m_lOutCount++] = (char)nC;
m_pbyBuffer[nR++] = (char)nC;
nR &amp;= (_LZH_N - 1);
}
else

{
int i = (nR - DecodePosition() - 1) &amp;
(_LZH_N - 1);
int j = nC - 255 + _LZH_THRESHOLD;
for (int k = 0;
k < j;
k++)
{
nC = m_pbyBuffer[(i + k) &amp;
(_LZH_N - 1)];
m_pcOut[m_lOutCount++] = (char)nC;
m_pbyBuffer[nR++] = (char)nC;
nR &amp;= (_LZH_N - 1);
}
}
}
m_lOut = m_lOutCount;
return TRUE;
}
void CCompress::StartHuff()
{
for (int i = 0;
i < _LZH_N_CHAR;
i++)
{
m_pwFreq = 1;
m_pnSon = i+_LZH_T;
m_pnParent[i+_LZH_T] = i;
}
i = 0;
int j = _LZH_N_CHAR;
while (j <= _LZH_R)
{
m_pwFreq[j] = m_pwFreq + m_pwFreq[i+1];
m_pnSon[j] = i;
m_pnParent = m_pnParent[i+1] = j;
i += 2;
j++;
}
m_pwFreq[_LZH_T] = 0xffff;
m_pnParent[_LZH_R] = 0;
}
short CCompress::DecodeChar()
{
WORD c = m_pnSon[_LZH_R];
while (c < _LZH_T)
{
c += GetBit();
c = m_pnSon[c];
}
c -= _LZH_T;
Update(c);
return c;
}
short CCompress::DecodePosition()
{
WORD i = GetByte();
WORD c = (WORD)d_code << 6;
WORD j = d_len - 2;
while (j--)
i = (i << 1) + GetBit();
return c | i &amp;
0x3f;
}
short CCompress::GetBit()
{
short i;
while (m_byGetLen <= 8)
{
if (m_lInCount < m_lIn)
i = (BYTE)m_pcIn[m_lInCount++];
else
i = 0;
m_wGetBuf |= i << (8 - m_byGetLen);
m_byGetLen += 8;
}
i = m_wGetBuf;
m_wGetBuf <<= 1;
m_byGetLen -= 1;
return (i < 0);
}
short CCompress::GetByte()
{
WORD i;
while (m_byGetLen <= 8)
{
if (m_lInCount < m_lIn)
i = (BYTE)m_pcIn[m_lInCount++];
else
i = 0;
m_wGetBuf |= i << (8 - m_byGetLen);
m_byGetLen += 8;
}
i = m_wGetBuf;
m_wGetBuf <<= 8;
m_byGetLen -= 8;
return i >> 8;
}
void CCompress::Update(short c)
{
short i, j, k, l;
if (m_pwFreq[_LZH_R] == _LZH_MAX_FREQ)
ReConstruct();
c = m_pnParent[c + _LZH_T];
do
{
k = ++m_pwFreq[c];
if (k > m_pwFreq[l = c + 1])
{
while (k > m_pwFreq[++l])
;
l--;
m_pwFreq[c] = m_pwFreq[l];
m_pwFreq[l] = k;
i = m_pnSon[c];
m_pnParent = l;
if (i < _LZH_T)
m_pnParent[i + 1] = l;
j = m_pnSon[l];
m_pnSon[l] = i;
m_pnParent[j] = c;
if (j < _LZH_T)
m_pnParent[j + 1] = c;
m_pnSon[c] = j;
c = l;
}
} while ((c = m_pnParent[c]) != 0); /*do
it until reaching the root */
}
void CCompress::ReConstruct()
{
short i, j, k;
WORD f, l;
j = 0;
for (i = 0;
i < _LZH_T;
i++)
{
if (m_pnSon >= _LZH_T)
{
m_pwFreq[j] = (m_pwFreq + 1) / 2;
m_pnSon[j] = m_pnSon;
j++;
}
}
for (i = 0, j = _LZH_N_CHAR;
j < _LZH_T;
i += 2, j++)
{
k = i + 1;
f = m_pwFreq[j] = m_pwFreq + m_pwFreq[k];
for (k = j - 1;
f < m_pwFreq[k];
k--)
;
k++;
l = (j - k) * 2;

memmove(&amp;m_pwFreq[k + 1], &amp;m_pwFreq[k], l);
m_pwFreq[k] = f;
memmove(&amp;m_pnSon[k + 1], &amp;m_pnSon[k], l);
m_pnSon[k] = i;
}
for (i = 0;
i < _LZH_T;
i++)
{
if ((k = m_pnSon) >= _LZH_T)
m_pnParent[k] = i;
else
m_pnParent[k] = m_pnParent[k + 1] = i;
}
}
BOOL CCompress::Encode()
{
short i, c, len, r, s, last_match_length;
memmove(m_pcOut, &amp;m_lIn, 4);

m_lInCount = 0;
m_lOutCount = 4;
m_wPutBuf = 0;
m_byPutLen = 0;
StartHuff();
InitTree();

s = 0;
r = _LZH_N - _LZH_F;
memset(m_pbyBuffer, ' ', r);

for (len = 0;
len < _LZH_F &amp;&amp;
m_lInCount < m_lIn;
len++)
m_pbyBuffer[r + len] = (BYTE)m_pcIn[m_lInCount++];
for (i = 1;
i <= _LZH_F;
i++)
InsertNode(r - i);
InsertNode(r);
do
{
if (m_nMatchLen > len)
m_nMatchLen = len;
if (m_nMatchLen <= _LZH_THRESHOLD)
{
m_nMatchLen = 1;
EncodeChar(m_pbyBuffer[r]);
}
else

{
EncodeChar(255 - _LZH_THRESHOLD + m_nMatchLen);
EncodePosition(m_nMatchPos);
}
last_match_length = m_nMatchLen;
for (i = 0;
i < last_match_length &amp;&amp;
m_lInCount < m_lIn;
i++)
{
DeleteNode(s);
c = (BYTE)m_pcIn[m_lInCount++];
m_pbyBuffer = (BYTE)c;
if (s < _LZH_F - 1)
m_pbyBuffer[s + _LZH_N] = (BYTE)c;
s = (s + 1) &amp;
(_LZH_N - 1);
r = (r + 1) &amp;
(_LZH_N - 1);
InsertNode(r);
}
while (i++ < last_match_length)
{
DeleteNode(s);
s = (s + 1) &amp;
(_LZH_N - 1);
r = (r + 1) &amp;
(_LZH_N - 1);
if (--len)
InsertNode(r);
}
} while (len > 0);
EncodeEnd();
m_lOut = m_lOutCount;
return TRUE;
}
void CCompress::InitTree()
{
for (int i = _LZH_N + 1;
i <= _LZH_N + 256;
i++)
m_pnRightSon = _LZH_NIL;
for (i = 0;
i < _LZH_N;
i++)
m_pnDad = _LZH_NIL;
}
void CCompress::InsertNode(short r)
{
short i, p, cmp;
BYTE *key;
WORD c;
cmp = 1;
key = &amp;m_pbyBuffer[r];
p = _LZH_N + 1 + key[0];
m_pnRightSon[r] = m_pnLeftSon[r] = _LZH_NIL;
m_nMatchLen = 0;
for ( ;
;
)
{
if (cmp >= 0)
{
if (m_pnRightSon[p] != _LZH_NIL)
p = m_pnRightSon[p];
else

{
m_pnRightSon[p] = r;
m_pnDad[r] = p;
return;
}
}
else

{
if (m_pnLeftSon[p] != _LZH_NIL)
p = m_pnLeftSon[p];
else

{
m_pnLeftSon[p] = r;
m_pnDad[r] = p;
return;
}
}
for (i = 1;
i < _LZH_F;
i++)
if ((cmp = key - m_pbyBuffer[p + i]) != 0)
break;
if (i > _LZH_THRESHOLD)
{
if (i > m_nMatchLen)
{
m_nMatchPos = ((r - p) &amp;
(_LZH_N - 1)) - 1;
if ((m_nMatchLen = i) >= _LZH_F)
break;
}
if (i == m_nMatchLen)
{
if ((c = ((r - p) &amp;
(_LZH_N - 1)) - 1) < m_nMatchPos)
m_nMatchPos = c;
}
}
}
m_pnDad[r] = m_pnDad[p];
m_pnLeftSon[r] = m_pnLeftSon[p];
m_pnRightSon[r] = m_pnRightSon[p];
m_pnDad[m_pnLeftSon[p]] = r;
m_pnDad[m_pnRightSon[p]] = r;
if (m_pnRightSon[m_pnDad[p]] == p)
m_pnRightSon[m_pnDad[p]] = r;
else
m_pnLeftSon[m_pnDad[p]] = r;
m_pnDad[p] = _LZH_NIL;
/* remove p */
}
void CCompress::DeleteNode(short p)
{
short q;
if (m_pnDad[p] == _LZH_NIL)
return; /* unregistered */
if (m_pnRightSon[p] == _LZH_NIL)
q = m_pnLeftSon[p];
else
if (m_pnLeftSon[p] == _LZH_NIL)
q = m_pnRightSon[p];
else

{
q = m_pnLeftSon[p];
if (m_pnRightSon[q] != _LZH_NIL)
{
do
{
q = m_pnRightSon[q];
} while (m_pnRightSon[q] != _LZH_NIL);
m_pnRightSon[m_pnDad[q]] = m_pnLeftSon[q];
m_pnDad[m_pnLeftSon[q]] = m_pnDad[q];
m_pnLeftSon[q] = m_pnLeftSon[p];
m_pnDad[m_pnLeftSon[p]] = q;
}
m_pnRightSon[q] = m_pnRightSon[p];
m_pnDad[m_pnRightSon[p]] = q;
}
m_pnDad[q] = m_pnDad[p];
if (m_pnRightSon[m_pnDad[p]] == p)
m_pnRightSon[m_pnDad[p]] = q;
else
m_pnLeftSon[m_pnDad[p]] = q;
m_pnDad[p] = _LZH_NIL;
}
void CCompress::EncodeChar(WORD c)
{
WORD i;
short j, k;
i = 0;
j = 0;
k = m_pnParent[c + _LZH_T];
do
{
i >>= 1;
if (k &amp;
1)
i += 0x8000;
j++;
} while ((k = m_pnParent[k]) != _LZH_R);
PutCode(j, i);
m_wCode = i;
m_wLen = j;
Update(c);
}
void CCompress::EncodePosition(WORD c)
{
WORD i;
i = c >> 6;
PutCode(p_len, (WORD)p_code << 8);
PutCode(6, (c &amp;
0x3f) << 10);
}
void CCompress::EncodeEnd()
{
if (m_byPutLen)
m_pcOut[m_lOutCount++] = m_wPutBuf >> 8;
}
void CCompress::PutCode(short l, WORD c)
{
m_wPutBuf |= c >> m_byPutLen;
if ((m_byPutLen += l) >= 8)
{
m_pcOut[m_lOutCount++] = m_wPutBuf >> 8;
if ((m_byPutLen -= 8) >= 8)
{
m_pcOut[m_lOutCount++] = (char)m_wPutBuf;
m_byPutLen -= 8;
m_wPutBuf = c << (l - m_byPutLen);
}
else

m_wPutBuf <<= 8;
}
}
void main()
{
CCompress *pMyComp;
pMyComp=new CCompress();
char TestBuf[256];
int i;
memset(TestBuf,0,256);
for(i=0;i<256;i++)
TestBuf='1';
memcpy(pMyComp->m_pcIn,TestBuf,256);
pMyComp->m_lIn=256;
pMyComp->Encode();
memcpy(pMyComp->m_pcIn,pMyComp->m_pcOut,pMyComp->m_lOut);
pMyComp->m_lIn=pMyComp->m_lOut;
pMyComp->Decode();

}
 
Java 里面没有无符号byte char类型,你可以将代码里面那些无符号字节数组声明为int类型
 
这样在字节右移的时候不会出现问题么?
 
右移没有问题,左移就要看移多少位了,你试试就可以知道了
 
我把上面的C程序改成了下面的Java代码,但在解压缩的时候总是不对,哪位大虾能帮我看看?
不甚感激!
package com.green.util.compress;
/**
* <p>Title: Compressed/decompress util.</p>
* <p>Description: Use to compress/decompress the data</p>
* <p>Copyright: Copyright (c) 2002</p>
* <p>Company: Green Co. LMT.</p>
* @author Hank
* @version 0.5
*/
public class Compress
{
//public section
public static final short _LZH_N=4096;
public static final short _LZH_F=60;
public static final short _LZH_THRESHOLD=2;
public static final short _LZH_NIL=_LZH_N;
public static final short _LZH_N_CHAR=(256 - _LZH_THRESHOLD + _LZH_F);
public static final short _LZH_T=(_LZH_N_CHAR * 2 - 1);
public static final short _LZH_R=(_LZH_T - 1);
public static final int _LZH_MAX_FREQ=0x8000;

short m_archrIn[]=null;
public long m_lIn;
short m_archrOut[]=null;
public long m_lOut;
//private:
private long m_lInCount;
private long m_lOutCount;
private short m_pbyBuffer[]=new short[_LZH_N + _LZH_F - 1];
private short m_nMatchPos;
private short m_nMatchLen;
private short m_pnLeftSon[]=new short[_LZH_N + 1];
private short m_pnRightSon[]=new short[_LZH_N + 257];
private short m_pnDad[]=new short[_LZH_N + 1];
private int m_pwFreq[]=new int[_LZH_T + 1];
private short m_pnParent[]=new short[_LZH_T + _LZH_N_CHAR];
private short m_pnSon[]=new short[_LZH_T];
private int m_wGetBuf;
private short m_byGetLen;
private int m_wPutBuf;
private short m_byPutLen;
private int m_wCode;
private int m_wLen;
short[] p_len= {
0x03, 0x04, 0x04, 0x04, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08
};
short[] p_code = {
0x00, 0x20, 0x30, 0x40, 0x50, 0x58, 0x60, 0x68,
0x70, 0x78, 0x80, 0x88, 0x90, 0x94, 0x98, 0x9C,
0xA0, 0xA4, 0xA8, 0xAC, 0xB0, 0xB4, 0xB8, 0xBC,
0xC0, 0xC2, 0xC4, 0xC6, 0xC8, 0xCA, 0xCC, 0xCE,
0xD0, 0xD2, 0xD4, 0xD6, 0xD8, 0xDA, 0xDC, 0xDE,
0xE0, 0xE2, 0xE4, 0xE6, 0xE8, 0xEA, 0xEC, 0xEE,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
};
short[] d_code = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,
0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A,
0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B, 0x0B,
0x0C, 0x0C, 0x0C, 0x0C, 0x0D, 0x0D, 0x0D, 0x0D,
0x0E, 0x0E, 0x0E, 0x0E, 0x0F, 0x0F, 0x0F, 0x0F,
0x10, 0x10, 0x10, 0x10, 0x11, 0x11, 0x11, 0x11,
0x12, 0x12, 0x12, 0x12, 0x13, 0x13, 0x13, 0x13,
0x14, 0x14, 0x14, 0x14, 0x15, 0x15, 0x15, 0x15,
0x16, 0x16, 0x16, 0x16, 0x17, 0x17, 0x17, 0x17,
0x18, 0x18, 0x19, 0x19, 0x1A, 0x1A, 0x1B, 0x1B,
0x1C, 0x1C, 0x1D, 0x1D, 0x1E, 0x1E, 0x1F, 0x1F,
0x20, 0x20, 0x21, 0x21, 0x22, 0x22, 0x23, 0x23,
0x24, 0x24, 0x25, 0x25, 0x26, 0x26, 0x27, 0x27,
0x28, 0x28, 0x29, 0x29, 0x2A, 0x2A, 0x2B, 0x2B,
0x2C, 0x2C, 0x2D, 0x2D, 0x2E, 0x2E, 0x2F, 0x2F,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
};
short[] d_len = {
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03, 0x03,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05, 0x05,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06, 0x06,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08,
};
public Compress()
{
m_wGetBuf = 0;
m_byGetLen = 0;
m_wPutBuf = 0;
m_byPutLen = 0;
m_archrIn=new short[128*1024];
m_archrOut=new short[128*1024];
m_lIn = 0;
m_lOut = 0;
}
public Compress(int len)
{
m_wGetBuf = 0;
m_byGetLen = 0;
m_wPutBuf = 0;
m_byPutLen = 0;
m_archrIn=new short[len];
m_archrOut=new short[len];
m_lIn = 0;
m_lOut = 0;
}
//=====================================================================begin
/**
* Use to compress the data
* @param data
* @return
*/
public byte[] compress(byte[] data)
{
//System.arraycopy(data, 0, this.m_archrIn, 0, data.length);
for(int i=0;
i<data.length;
i++)
{
this.m_archrIn=(short)data;
}
this.m_lIn=data.length;
encode();
int retLen=(int)m_lOut;
byte[] ret=new byte[retLen];
for(int i=0;
i<retLen;
i++)
{
ret=(byte)m_archrOut;
}
return ret;
}
/**
* Use to decompress the data
* @param data
* @return
*/
public byte[] decompress(byte[] data)
{
//System.arraycopy(data, 0, this.m_archrIn, 0, data.length);
for(int i=0;
i<data.length;
i++)
{
this.m_archrIn=(short)data;
}
this.m_lIn=data.length;
decode();
int retLen=(int)m_lOut;
byte[] ret=new byte[retLen];
for(int i=0;
i<retLen;
i++)
{
ret=(byte)m_archrOut;
}
return ret;
}
//=======================================================================END

/**
* Use to encode the input array
* @return
*/
public boolean encode()
{
short i, c, len, r, s, last_match_length;
m_archrOut[0] = (short)m_lIn;
m_archrOut[1] = (short)(m_lIn >> 8 &amp;
0xff);
m_archrOut[2] = (short)(m_lIn >> 16 &amp;
0xff);
m_archrOut[3] = (short)(m_lIn >> 24 &amp;
0xff);
m_lInCount = 0;
m_lOutCount = 4;
m_wPutBuf = 0;
m_byPutLen = 0;
startHuff();
initTree();
s = 0;
r = _LZH_N - _LZH_F;
for(int m=0;m<r;m++)
m_pbyBuffer[m]=' ';
for (len = 0;
len < _LZH_F &amp;&amp;
m_lInCount < m_lIn;
len++)
m_pbyBuffer[r + len] = (byte)m_archrIn[(int)m_lInCount++];
for (i = 1;
i <= _LZH_F;
i++)
insertNode((short)(r - i));
insertNode(r);
do
{
if (m_nMatchLen > len)
m_nMatchLen = len;
if (m_nMatchLen <= _LZH_THRESHOLD)
{
m_nMatchLen = 1;
encodeChar(m_pbyBuffer[r]);
}
else
{
encodeChar((byte)(255 - _LZH_THRESHOLD + m_nMatchLen));
encodePosition(m_nMatchPos);
}
last_match_length = (short)m_nMatchLen;
for (i = 0;
i < last_match_length &amp;&amp;
m_lInCount < m_lIn;
i++)
{
deleteNode(s);
c = (byte)m_archrIn[(int)m_lInCount++];
m_pbyBuffer = (byte)c;
if (s < _LZH_F - 1)
m_pbyBuffer[s + _LZH_N] = (byte)c;
s = (short)((s + 1) &amp;
(_LZH_N - 1));
r = (short)((r + 1) &amp;
(_LZH_N - 1));
insertNode(r);
}
while (i++ < last_match_length)
{
deleteNode(s);
s = (short)((s + 1) &amp;
(_LZH_N - 1));
r = (short)((r + 1) &amp;
(_LZH_N - 1));
--len;
if (len!=0)
insertNode(r);
}
}
while (len > 0);
encodeEnd();
m_lOut = m_lOutCount;
return true;
}
/**
* Use to decode the
* @return
*/
public boolean decode()
{
long lSize=0;
int m = ((m_archrIn[3] &amp;
0xff) << 24) + ((m_archrIn[2] &amp;
0xff) << 16) + ((m_archrIn[1] &amp;
0xff) << 8) + (m_archrIn[0] &amp;
0xff);
lSize=m;

if (lSize == 0)
return false;
m_lInCount = 4;
m_lOutCount = 0;
m_wGetBuf = 0;
m_byGetLen = 0;
startHuff();
int nR = _LZH_N - _LZH_F;
//for(int i=0;i<nR;i++)
// m_pbyBuffer='';
for (m_lOutCount = 0;
m_lOutCount < lSize;
)
{
short nC = decodeChar();
if (nC < 256)
{
m_archrOut[(int)m_lOutCount++] = nC;
m_pbyBuffer[nR++] = nC;
nR &amp;= (_LZH_N - 1);
}
else
{
int i = (nR - decodePosition() - 1) &amp;
(_LZH_N - 1);
int j = nC - 255 + _LZH_THRESHOLD;
for (int k = 0;
k < j;
k++)
{
nC = m_pbyBuffer[(i + k) &amp;
(_LZH_N - 1)];
m_archrOut[(int)m_lOutCount++] = nC;
m_pbyBuffer[nR++] = nC;
nR &amp;= (_LZH_N - 1);
}
}
}
m_lOut = m_lOutCount;
return true;
}
private void startHuff()
{
for (int i = 0;
i < _LZH_N_CHAR;
i++)
{
m_pwFreq = 1;
m_pnSon = (short)(_LZH_T+i);
m_pnParent[i+_LZH_T] = (short)i;
}
int i = 0;
int j = _LZH_N_CHAR;
while (j <= _LZH_R)
{
m_pwFreq[j] = m_pwFreq + m_pwFreq[i+1];
m_pnSon[j] = (short)i;
m_pnParent = m_pnParent[i+1] = (short)j;
i += 2;
j++;
}
m_pwFreq[_LZH_T] = 0xffff;
m_pnParent[_LZH_R] = 0;
}

short decodeChar()
{
int c = m_pnSon[_LZH_R];
while (c < _LZH_T)
{
c += getBit();
c = m_pnSon[c];
}
c -= _LZH_T;
update((short)c);
return (short)c;
}
short decodePosition()
{
int i = getByte();
int c = d_code << 6;
int j = d_len - 2;
//j--;
while(j!=0)
{
j--;
i = (i << 1) + getBit();
}
return (short)(c | i &amp;
0x3f);
}
short getBit()
{
short i;
while (m_byGetLen <= 8)
{
if (m_lInCount < m_lIn)
i = m_archrIn[(int)m_lInCount++];
else
i = 0;
m_wGetBuf |= i << (8 - m_byGetLen);
m_byGetLen += 8;
}
i = (short)m_wGetBuf;
m_wGetBuf <<= 1;
m_byGetLen -= 1;
short ret=0;
if(i<0)
{
ret=1;
}
return ret;
}
short getByte()
{
int i;
while (m_byGetLen <= 8)
{
if (m_lInCount < m_lIn)
i = m_archrIn[(int)m_lInCount++];
else
i = 0;
m_wGetBuf |= i << (8 - m_byGetLen);
m_byGetLen += 8;
}
i = m_wGetBuf;
m_wGetBuf <<= 8;
m_byGetLen -= 8;
return (short)(i >> 8);
}
private void update(short c)
{
short i, j, k, l;
if (m_pwFreq[_LZH_R] == _LZH_MAX_FREQ)
reconstruct();
c = (short)m_pnParent[c + _LZH_T];
do
{
k = (short)(++m_pwFreq[c]);
l = (short)(c + 1);
//if (k > m_pwFreq[l] &amp;&amp;
l<m_pwFreq.length-1)
if (k > m_pwFreq[l])
{
while (k > m_pwFreq[++l])
;
l--;
m_pwFreq[c] = m_pwFreq[l];
m_pwFreq[l] = k;
i = (short)m_pnSon[c];
m_pnParent = l;
if (i < _LZH_T)
m_pnParent[i + 1] = l;
j = (short)m_pnSon[l];
m_pnSon[l] = i;
m_pnParent[j] = c;
if (j < _LZH_T)
m_pnParent[j + 1] = c;
m_pnSon[c] = j;
c = l;
}
}
while ((c = (short)m_pnParent[c]) != 0); /*do
it until reaching the root */
}
void reconstruct()
{
short i, j, k;
int f, l;
j = 0;
for (i = 0;
i < _LZH_T;
i++)
{
if (m_pnSon >= _LZH_T)
{
m_pwFreq[j] = (m_pwFreq + 1) / 2;
m_pnSon[j] = m_pnSon;
j++;
}
}
for (i = 0, j = _LZH_N_CHAR;
j < _LZH_T;
i += 2, j++)
{
k = (short)(i + 1);
f = m_pwFreq[j] = (m_pwFreq + m_pwFreq[k]);
for (k =(short)(j - 1);
f < m_pwFreq[k];
k--)
;
k++;
l = (j - k) * 2;
System.arraycopy(m_pwFreq,k,m_pwFreq,k+1,l);
m_pwFreq[k] = f;
System.arraycopy(m_pnSon, k, m_pnSon, k+1,l);
m_pnSon[k] = i;
}
for (i = 0;
i < _LZH_T;
i++)
{
if ((k = (short)m_pnSon) >= _LZH_T)
m_pnParent[k] = i;
else
m_pnParent[k] = m_pnParent[k + 1] =i;
}
}

void initTree()
{
for (int i = _LZH_N + 1;
i <= _LZH_N + 256;
i++)
m_pnRightSon = _LZH_NIL;
for (int i = 0;
i < _LZH_N;
i++)
m_pnDad = _LZH_NIL;
}
void insertNode(short r)
{
short i, p, cmp;
int len=m_pbyBuffer.length;
short key[]=new short[len-r];
int c;
cmp = 1;
System.arraycopy(m_pbyBuffer,(int)r,key,0,len-r);
p = (short)(_LZH_N + 1 + key[0]);
m_pnRightSon[r] = m_pnLeftSon[r] = _LZH_NIL;
m_nMatchLen = 0;
for ( ;
;
)
{
if (cmp >= 0)
{
if (m_pnRightSon[p] != _LZH_NIL)
p = (short)(m_pnRightSon[p]);
else
{
m_pnRightSon[p] = r;
m_pnDad[r] = p;
return;
}
}
else
{
if (m_pnLeftSon[p] != _LZH_NIL)
p = (short)(m_pnLeftSon[p]);
else
{
m_pnLeftSon[p] = r;
m_pnDad[r] = p;
return;
}
}
for (i = 1;
i < _LZH_F;
i++)
if ((cmp = (short)(key - m_pbyBuffer[p + i])) != 0)
break;
if (i > _LZH_THRESHOLD)
{
if (i > m_nMatchLen)
{
m_nMatchPos =(short)(((r - p) &amp;
(_LZH_N - 1)) - 1);
if ((m_nMatchLen = i) >= _LZH_F)
break;
}
if (i == m_nMatchLen)
{
if ((c = ((r - p) &amp;
(_LZH_N - 1)) - 1) < m_nMatchPos)
m_nMatchPos =(short)c;
}
}
}
m_pnDad[r] = m_pnDad[p];
m_pnLeftSon[r] = m_pnLeftSon[p];
m_pnRightSon[r] = m_pnRightSon[p];
m_pnDad[m_pnLeftSon[p]] = r;
m_pnDad[m_pnRightSon[p]] = r;
if (m_pnRightSon[m_pnDad[p]] == p)
m_pnRightSon[m_pnDad[p]] = r;
else
m_pnLeftSon[m_pnDad[p]] = r;
m_pnDad[p] = _LZH_NIL;
/* remove p */
}
void deleteNode(short p)
{
short q;
if (m_pnDad[p] == _LZH_NIL)
return; /* unregistered */
if (m_pnRightSon[p] == _LZH_NIL)
q = (short)m_pnLeftSon[p];
else
{
if (m_pnLeftSon[p] == _LZH_NIL)
q = (short)m_pnRightSon[p];
else
{
q = (short)m_pnLeftSon[p];
if (m_pnRightSon[q] != _LZH_NIL)
{
do
{
q = (short)m_pnRightSon[q];
}
while (m_pnRightSon[q] != _LZH_NIL);
m_pnRightSon[m_pnDad[q]] = m_pnLeftSon[q];
m_pnDad[m_pnLeftSon[q]] = m_pnDad[q];
m_pnLeftSon[q] = m_pnLeftSon[p];
m_pnDad[m_pnLeftSon[p]] = q;
}
m_pnRightSon[q] = m_pnRightSon[p];
m_pnDad[m_pnRightSon[p]] = q;
}
}
m_pnDad[q] = m_pnDad[p];
if (m_pnRightSon[m_pnDad[p]] == p)
m_pnRightSon[m_pnDad[p]] = q;
else
m_pnLeftSon[m_pnDad[p]] = q;
m_pnDad[p] = _LZH_NIL;
}
void encodeChar(int c)
{
int i;
short j, k;
i = 0;
j = 0;
k =(short)m_pnParent[c + _LZH_T];
do
{
i >>= 1;
if ((k &amp;
1)!=0)
i += 0x8000;
j++;
}while ((k = (short)m_pnParent[k]) != _LZH_R);
putCode(j, i);
m_wCode = i;
m_wLen = j;
update((short)c);
}
void encodePosition(int c)
{
int i;
i = c >> 6;
putCode((short)p_len, p_code << 8);
putCode((short)6, (c &amp;
0x3f) << 10);
}
void encodeEnd()
{
if (m_byPutLen!=0)
m_archrOut[(int)m_lOutCount++] = (short)(m_wPutBuf >> 8);
}
void putCode(short l, int c)
{
m_wPutBuf |= c >> m_byPutLen;
if ((m_byPutLen += l) >= 8)
{
m_archrOut[(int)m_lOutCount++] = (short)(m_wPutBuf >> 8);
if ((m_byPutLen -= 8) >= 8)
{
m_archrOut[(int)m_lOutCount++] = (short)(m_wPutBuf);
m_byPutLen -= 8;
m_wPutBuf = c << (l - m_byPutLen);
}
else
{
m_wPutBuf <<= 8;
}
}
}
}
 
Java中有byte类型,8个位!
但这个算法有存在的必要吗?为何不用Java中的 ZIP 或 GZIP 流,可以很方便地操作
ZIP 格式文件!
 
没办法,我需要与另外一个程序通讯,该程序传给我的数据全部都是经过LZH算法压缩的。
Java中的byte不能够表示无符号的8位整数,所以我只好用short型来代替了!
不知道各位有没有更好的办法?
非常感谢!
 
unsighed byte 值是 0 ~ 255
Java 里面byte 是 -127 ~ 127
如果一个Java里面的byte b,你简单使用
int i = b &amp;
0xFF ;
或者
int i = b >=0 ? b: b+256;
不保留符号位就转换为了unsighed byte,另外,这么一堆代码压上来,我有心帮你也给吓跑
了,大哥我自己还有一堆RFC 2865,2866相关的RADIUS操作代码搞不定呢,谁想看看吗?
 
你先用java中与c中数据类型所占字节数相同的类型,然后将这种类型扩展到字节数更大的类型就
可以用了。比如c中的用unsigned byte, 你在java中先用byte,然后将其转换为short或int就
可以获得正确的值。
 
后退
顶部