primitive « cast « Java Data Type Q&A





1. Primitive type 'short' - casting in Java    stackoverflow.com

I have a question about the primitive type 'short' in Java. I am using JDK 1.6. If I have the following:

short a = 2;
short b = 3;
short c = a ...

2. Casting primitive data types    stackoverflow.com

public class TestEmployee {
    public static void main(String args[]) { 
          byte b=(byte)1*200;
       ...

3. Weird java behavior with casts to primitive types    stackoverflow.com

This was probably asked somewhere but I couldn't find it. Could someone clarify why this code compiles and prints out 1?

long i = (byte) + (char) - (int) + (long) - ...

4. Primitive casting    coderanch.com

Hi, float a = 23.23f; int b = a; //Fails to compile int i = (int)a; //Compiles ------ int c = 123; float d = c; //Compiles ------ My questions is, when both float and int are of size 32 bits, why the relation between float and int types is not symmetric? Thanks, -Vijay

5. casting of primitives    coderanch.com

Hi, I am trying cast a number to a long using the foll piece of code: long x = (long) 2592000000; Even though the number is within the range of the primitive 'long' it complains that it is out of range with the error saying 'int out of range' BTW, if instead of that I write it as long x = ...

6. Primitive Casting    coderanch.com

Write out a short list (no pun intended) of the minimum and maximum values for byte, short, and int and memorize it. I've memorized them simply from reading and typing them over the last 20 years, but even still I only know the maximum int to a few decimal places (2.147 billion something). My apologies if this offends anyone, but this ...

7. Primitive type casting    coderanch.com

First, look at the bit representation of 900,000. 11011011101110100000 Since a short only contains 16 bits, we are only concerned with the last 16 bits. 1011101110100000 Since the first bit is 1, this is a negative number. To determine what negative number it is, we flip each of the bits and add 1. When we flip the bits we get 0100010001011111 ...

8. Primitive casting    coderanch.com

Hi, float a = 23.23f; int b = a; //Fails to compile int i = (int)a; //Compiles ------ int c = 123; float d = c; //Compiles ------ My questions is, when both float and int are of size 32 bits, why the relation between float and int types is not symmetric? Thanks, -Vijay

9. primitive casting    coderanch.com





10. primitive casting    coderanch.com

Hi sonia, You cannot do cast from long to byte.(Because,long is made up of 8 bytes of data).If you try to do then your data gets last. Consider this code long long_no = 127; byte byte_no = (byte)long_no; System.out.println("Long value is:"+long_no+"Byte value is:"+byte_no); You will get both the values same.But,once you increase the value of long_no to more than 127 your ...

11. primitive type casting    forums.oracle.com

12. auto cast in primitive problem    forums.oracle.com