为什么这段代码不能在Java中运行?

为什么这段代码不能在Java中运行?,java,android,c,pcm,Java,Android,C,Pcm,可能重复: 我有一个将ulaw音乐转换为pcm格式的代码 代码是用C编写的,但现在,我需要它在java中运行 代码是这样的 short ALG_ulawDecode(unsigned short input) { unsigned short isNegative; short nOut; isNegative = ((input & 0x80) == 0); if (isNegative) nOut = 127 - input; else nOut = 255 -

可能重复:

我有一个将ulaw音乐转换为pcm格式的代码

代码是用C编写的,但现在,我需要它在java中运行

代码是这样的

short ALG_ulawDecode(unsigned short input)
{
unsigned short isNegative;

short nOut;

isNegative = ((input & 0x80) == 0);
if (isNegative)
    nOut = 127 - input;
else
    nOut = 255 - input;
if (nOut < 2)
    nOut *= 2;
else if (nOut < 16)
    nOut = ((nOut - 1) << 1) + 1 + 1;
else if (nOut < 32)
    nOut = ((nOut - 16) << 2) + 2 + 31;
else if (nOut < 48)
    nOut = ((nOut - 32) << 3) + 4 + 95;
else if (nOut < 64)
    nOut = ((nOut - 48) << 4) + 8 + 223;
else if (nOut < 80)
    nOut = ((nOut - 64) << 5) + 16 + 479;
else if (nOut < 96)
    nOut = ((nOut - 80) << 6) + 32 + 991;
else if (nOut < 112)
    nOut = ((nOut - 96) << 7) + 64 + 2015;
else
    nOut = ((nOut - 112) << 8) + 128 + 4063;
if (isNegative)
    nOut = -nOut;
nOut <<= 2;
return nOut;
}
它无法运行,因为Java不支持『unsigned short』

有人有什么建议吗


谢谢你的帮助

任何人都能给你的最好建议是去读Java入门教程或书籍


正如错误所述,unsigned short在Java中不是原语。

Java没有有符号和无符号类型。除去unsigned和used signed short,剩下的代码应该仍然可以工作。

char在语法上等同于Java中的unsigned short。但是,最好不要将它用于任何公共方法,因为它在语义上不是整数类型


如果你想用unsignedshort,我认为int是合适的。你可以使用它的最低16位。< /p>写C或C++。在Java中不能有未签名的短字符。