// operators/Literals.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.public class Literals {public static void main(String[] args) {int i1 = 0x2f; // Hexadecimal (lowercase)System.out.println("i1: " + Integer.toBinaryString(i1));int i2 = 0X2F; // Hexadecimal (uppercase)System.out.println("i2: " + Integer.toBinaryString(i2));int i3 = 0177; // Octal (leading zero)System.out.println("i3: " + Integer.toBinaryString(i3));char c = 0xffff; // max char hex valueSystem.out.println("c: " + Integer.toBinaryString(c));byte b = 0x7f; // max byte hex value 10101111;System.out.println("b: " + Integer.toBinaryString(b));short s = 0x7fff; // max short hex valueSystem.out.println("s: " + Integer.toBinaryString(s));long n1 = 200L; // long suffixlong n2 = 200l; // long suffix (can be confusing)long n3 = 200;// Java 7 Binary Literals:byte blb = (byte)0b00110101;System.out.println("blb: " + Integer.toBinaryString(blb));short bls = (short)0B0010111110101111;System.out.println("bls: " + Integer.toBinaryString(bls));int bli = 0b00101111101011111010111110101111;System.out.println("bli: " + Integer.toBinaryString(bli));long bll = 0b00101111101011111010111110101111;System.out.println("bll: " + Long.toBinaryString(bll));float f1 = 1;float f2 = 1F; // float suffixfloat f3 = 1f; // float suffixdouble d1 = 1d; // double suffixdouble d2 = 1D; // double suffix// (Hex and Octal also work with long)}}/* Output:i1: 101111i2: 101111i3: 1111111c: 1111111111111111b: 1111111s: 111111111111111blb: 110101bls: 10111110101111bli: 101111101011111010111110101111bll: 101111101011111010111110101111*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。