zoukankan      html  css  js  c++  java
  • Java7 新特性 数值文本表示法

    今天和大家分享下 java7中新特性-数值文本表示法

    首先,在原来jdk1.6中 如果需要将一个二进制的数值转换成十进制的话,一般情况下都会以下面的代码方式去实现。

    1     public static void main(String[] args) {
    2         
    3         int res = Integer.parseInt("1100110", 2);
    4         System.out.println(res);
    5     }

    现在在jdk7中 我们可以这样写,来简化 二进制转换成十进制 方法:

    1     public static void main(String[] args) {
    2         
    3         int res = 0b1100110;
    4         System.out.println(res);
    5     }

    -------------------------------------

    同理可以将 八进制、十六进制进行转换:

    以下描述为 十六进制转换

    jdk6写法

    1     public static void main(String[] args) {
    2         
    3         int res = Integer.parseInt("A", 16);
    4         System.out.println(res);
    5     }

    jdk7写法

    1     public static void main(String[] args) {
    2         
    3         int res = 0xA;
    4         System.out.println(res);
    5     }

    -------------------------------------

    以下描述为 八进制转换

    jdk6写法

    1     public static void main(String[] args) {
    2         
    3         int res = Integer.parseInt("11",8);
    4         System.out.println(res);
    5     }

    jdk7写法

    1     public static void main(String[] args) {
    2         
    3         int res = 011;
    4         System.out.println(res);
    5     }

    -------------------------------------

    总结:

    在jdk7 中 表示 二、八、十六 进制 转换成十进制表示:

    二进制:    int res = 0b110;

    八进制:    int res = 0110;

    十六进制: int res = 0xA;

  • 相关阅读:
    eclipse中SVN分支合并到主干
    Nginx+Php-fpm+MySQL+Redis源代码编译安装指南
    php-fpm的重启/关闭
    修改PHP上传文件大小限制的方法
    【转】Android AlertDialog自定义布局
    unity 多线程
    今天无意中发现的WWW.threadPriority
    Socket.IO for Unity 简要介绍
    shader一般都是用工具调试的
    METAL渲染是什么?
  • 原文地址:https://www.cnblogs.com/zhonghuazhi/p/3488376.html
Copyright © 2011-2022 走看看