-1

Possible Duplicate:
unsigned short in java
Conversion of Audio Format in JAVA

i Have a code which convert ulaw music to pcm format

The Code is programed by C , but now, i need it run in java

the Code is like this

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;
}

It just can't run due to 『unsigned short』are not supported in Java

is anyone have some advice?

Thanks for help!

Community
  • 1
  • 1
Bird Hsuie
  • 690
  • 7
  • 15

3 Answers3

2

The best advice anyone can give you is to go read an introduction to Java tutorial or book.

As the error states, unsigned short is not a primitive in Java.

Alex DiCarlo
  • 4,851
  • 18
  • 34
2

Java doesn't have signed and unsigned types. Remove the unsigned and used signed shorts, the rest of the code should still work.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
1

char is grammatically equivalent to unsigned short in Java. However, you'd better not use it for any public methods as it is semantically not an integer type.

If you want to use unsigned short, I think int fits. You can just use the lowest 16 bits of it.

shuangwhywhy
  • 5,475
  • 2
  • 18
  • 28