How big is an int in Java

Integer Data types in Java



 // 8 bits // -128 to 127 0000 0001

b = -128;
System.out.println("b " + b);
b = 127;
System.out.println("b " + b);


// short integer  in Java
// 00000000 00000000
short s = (short)b; // 16 bit // cast from a number datatype to another number datatype
s = 500;
b = (byte)s;
System.out.println("b " + b);


// int in Java
// 00000000 00000000 00000000 00000001
int i = (int)s ; // 32 bit ; binary integer 0 1 ; 00000000 8 bits= 1byte

// long integer in Java
// 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001
long l = (long)i; // 64-bit

// float in Java
// single-precision 32-bit
// 0 and manitissa of 23 bits and exponent of 8 bits
// 0.01234567900123456789012 x 10*12345678
float f = 0.0f;

// double in Java
double d = 3048575658.00 * 728348716381.00; // double-precision 64-bit

d = (double) f; // cast float to double double-precision 64-bit


Comments

Popular posts from this blog

The Seven Different Types of Coding Blocks in Java

What is a web application? (Lesson 7 of our Java Bootcamp)