Literals

Uppercase or lowercase L means long (however, using a lowercase l is confusing because it can look like the number one)

long l = 200L;

Uppercase or lowercase F means float.

float f = 200F;

Uppercase or lowercase D means double.

double d = 200D;

 

Hexadecimal (base 16), which works with all the integral data types, is denoted by a leading 0x or 0X followed by 0-9 or a-f either in uppercase or lowercase.

Notice in the preceding code the maximum possible hexadecimal values for char, byte, and short.

char c = 0Xffff;
byte b = 0X7f;
short s = 0X7fff;

Octal (base 8) is denoted by a leading zeroin the number and digits from 0-7.

int i = 0200;

 

This is easily accomplished with the static toBinaryString( ) methods from the Integer and Long classes.

Notice that when passing smaller types to Integer.toBinaryString( ), the type is automatically converted to an int.

posted on 2014-09-23 15:19  技术员  阅读(338)  评论(0编辑  收藏  举报

导航