short « Integer « Java Data Type Q&A





1. Writing a function: short GetBits(short data, int p, int n)    stackoverflow.com

I am writing a function short getBits(short data, int p, int n) I have tried:

public static short getBits(short data, int p, int n) {
 short bitmask = (short) ((~0 << (16 ...

2. Which is better? To use short or int?    stackoverflow.com

In Java or C++: Which is better? To use short or int for numbers that go to the short Max value, from 0 to 65535 in the case of unsigned short in ...

3. java converting int to short    stackoverflow.com

I am calculating 16 bit checksum on my data which i need to send to server where it has to recalculate and match with the provided checksum. Checksum value that i ...

4. inconvertible types found : int required: java.lang.Short    stackoverflow.com

I was given this source code and asked to compile it: it fails with the error " inconvertible types found : int required: java.lang.Short". The code does a bitwise ...

5. Why does Java convert byte and short operands to ints during numeric promotion    stackoverflow.com

What are the reasons behind the extension of small datatypes (e.g. byte) to int during the Numeric Promotion process? Wouldn't it be possible to perform most of the operations ...

6. How expensive it is to cast from int to short in Java    stackoverflow.com

In terms of runtime performance, how expensive it is to cast int to short in Java? There may be thousands of such casting, hence I wonder if it would impact the ...

7. Convert int to unsigned short java    stackoverflow.com

I have written a .obj parser in java to modelize 3D objects on iPhone. I would like to export the data as a binary file, which must be as small as ...

8. Convert Integer to Short    coderanch.com

Hi all i intend to convert a integer (or short or long) that is greater than a byte can hold (eg, 1111) to a byte array, since casting is simply cannot be used here, any other way can do it without lose precise? I have tried to use Integer wrapper class and use its toBinaryString() to convert the int to a ...





10. int -> byte , short , char    coderanch.com

byte b = 23 ; a literal ( should not be fraction ) is always int by default . But compiler automatically cast if the literal is in limit of byte . So above statement is perfect . byte b1 = 4; byte b2 = 6; byte add = b1+b2; why it doesn't work . the result will come 10 ( ...

11. byte short int long    coderanch.com

Good question. I guess it just comes down to using the right tool for the right job. Granted, memory is cheap, and we don't have to be as frugal with it as in the old days. However there's still no need to squander it recklessly. In communications applications, you're not just talking about memory, you're talking about bits being sent across ...

12. Integer and Short    coderanch.com

public class Testing { public static void main(String[] args) { System.out.println("Integer.valueOf:" +Integer.valueOf("101", 2)); System.out.println("Integer.toBinaryString:" +Integer.toBinaryString(5)); System.out.println("Integer.toString:" +Integer.toString(5, 2)); System.out.println("Short.valueOf:" +Short.valueOf("101", 2)); // System.out.println("Short.toString:" +Short.toString((short)5, 2)); <-- not available for short } } Why do we need the methods like Integer.toBinaryString(5)just for Integer and Long in Java. Integer.toString(5, 2) can do the same thing. Also, why dont we have a toString methods ...

13. Convert short to int with & 0xffff    coderanch.com

I'm very new to Java, so please bear with me. I am trying to make a small plugin for the ImageJ program. I've successfully used some sample code to read the pixels of a 16-bit image into a short array. short[] pixels = (short[])ip.getPixels(); I need to do some calculations on the pixels, and I would like to convert them to ...

14. Do cast from int to short    coderanch.com

15. inconvertible types found : int required: java.lang.Short    coderanch.com

]Fixed: changed Short to short. Compiled without errors. Hello, I was given this source code and asked to compile it: it fails with the error " inconvertible types found : int required: java.lang.Short". The code does a bitwise shift to convert some hashed (I think) values to integer. The compiler fails when encountering this statement "s >>>= 5;" ... try {... ...

16. Convert Signed Short to Integer    coderanch.com





18. Question about a switch condition with int and short variables.    forums.oracle.com

I am quoting from the SCJP book by Sierra and Bates. "When a program encounters the keyword break during the execution of a switch statement, execution will immediately move out of the switch block to the next statement after the switch. If break is omitted, the program just keeps executing the remaining case blocks until either a break is found or ...

19. Type casts (short / integer)    forums.oracle.com

20. Integer, Short object comparision problem (unexpected behaviour)    forums.oracle.com

b1 = 51; b2 = 51; System.out.printf("Byte(%s,hash:%s) == Byte(%s,hash:%s), Result(%s)\n", b1, b1.hashCode(), b2, b2.hashCode(), b1 == b2); b1 = 127; b2 = 127; System.out.printf("Byte(%s,hash:%s) == Byte(%s,hash:%s), Result(%s)\n", b1, b1.hashCode(), b2, b2.hashCode(), b1 == b2); a1 = 51; a2 = 51; System.out.printf("Integer(%s,hash:%s) == Integer(%s,hash:%s), Result(%s)\n", a1, a1.hashCode(), a2, a2.hashCode(), a1 == a2); a1 = 127; a2 = 127; System.out.printf("Integer(%s,hash:%s) == Integer(%s,hash:%s), Result(%s)\n", ...