博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
计算器的二进制功能java_Java二进制文字– Java 7功能
阅读量:2529 次
发布时间:2019-05-11

本文共 1412 字,大约阅读时间需要 4 分钟。

计算器的二进制功能java

Binary literals are new features in Java 7. As you all know that we can write integral types (byte, short, int, and long) in Binary and Hexadecimal formats. However, from Java 7 onwards we can write these numbers in binary format also. The number should be prefixed with 0b or 0B to be treated as binary literal.

二进制文字是Java 7中的新功能。众所周知,我们可以用二进制和十六进制格式编写整数类型(字节,短,整数和长整数)。 但是,从Java 7开始,我们也可以用二进制格式编写这些数字。 该数字应以0b0B为前缀,以将其视为二进制文字。

Java中的二进制文字 (Binary Literals in Java)

This feature is very helpful to bit-oriented systems like processors, network protocols and bitmapped hardware device. Earlier the programmers used to transform from binary to decimal/hexadecimal and vice versa. Using this feature will remove this transformation and chances of error will be less in this conversion.

此功能对于面向位的系统(例如处理器,网络协议和位图硬件设备)非常有帮助。 以前,程序员曾经从二进制转换为十进制/十六进制,反之亦然。 使用此功能将删除此转换,并且此转换中出错的机会会减少。

Also, the code using bitwise operations will be more readable with this feature.

而且,使用按位运算的代码将通过此功能更易读。

Let’s see binary literals in action with a simple java program:

让我们看一下使用简单的Java程序执行的二进制文字:

package com.journaldev.util;public class Java7Literals {	public static void main(String[] args) {		int i=0b0111;		byte b=(byte) 0b0111;		long l=(long) 0B0111L;		System.out.println("i="+i);		System.out.println("b="+b);		System.out.println("l="+l);	}}

Output of the above program is:

上面程序的输出是:

i=7b=7l=7x=7

翻译自:

计算器的二进制功能java

转载地址:http://mklzd.baihongyu.com/

你可能感兴趣的文章
travis CI
查看>>
2nd 词频统计更新
查看>>
转载------------java 进程创建
查看>>
0day漏洞
查看>>
JS正则表达式大全
查看>>
loadrunner——常见函数
查看>>
网页细分图结果分析(Web Page Diagnostics)
查看>>
Java 构造方法、构造方法重载、复制构造方法
查看>>
创建可重用的对象
查看>>
在CentOS构造内核树----通过yum方式(智能化方式)
查看>>
zabbix如何监控WEB应用性能
查看>>
软件工程——理论、方法与实践 第九章
查看>>
mac环境下mongodb的安装和使用
查看>>
实验9 根据材料编程
查看>>
网站架构
查看>>
Request.QueryString 和 Request.Param的区别
查看>>
CSS技巧(一):清除浮动
查看>>
狄利克雷分布
查看>>
atitit. 研发管理---如何根据自己的特挑选 产业、行业、职业、岗位与自己发展的关系...
查看>>
Atitit. WordPress 4.2.2新特性对比 attilax总结
查看>>