本文介绍了在Java中有二进制文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想通过一个二进制字面值申报我的整数。是否有可能在Java中?

I want to declare my integer number by a binary literal. Is it possible in Java?

推荐答案

看此链接:

http://en.wikibooks.org/wiki/Java_Programming/Literals/Numeric_Literals/Integer_Literals

在Java中,您可以在多种格式输入整数:

In Java, you may enter integer numbers in several formats:

1)为小数,如1995年,51966.负十进制数字,例如-42实际上是由整数字面含义与一元否定操作前pressions。

1) As decimal numbers such as 1995, 51966. Negative decimal numbers such as -42 are actually expressions consisting of the integer literal with the unary negation operation.

2)为八进制数字,用前导0(零)数字,一个或多个附加八进制数字(0-7),如077八进制数字可以计算为负数之间的数字;例如037777777770实际上是十进制值-8。

2) As octal numbers, using a leading 0 (zero) digit and one or more additional octal digits (digits between 0 and 7), such as 077. Octal numbers may evaluate to negative numbers; for example 037777777770 is actually the decimal value -8.

3)作为后跟一个或多个十六进制数字十六进制数字,使用格式为0x(或0X)(数字从0到9,A到F或A到F)。例如,0xCAFEBABEL是长整数3405691582.像八进制数,十六进制文字可能会重新present负数。

3) As hexadecimal numbers, using the form 0x (or 0X) followed by one or more hexadecimal digits (digits from 0 to 9, a to f or A to F). For example, 0xCAFEBABEL is the long integer 3405691582. Like octal numbers, hexadecimal literals may represent negative numbers.

启动在J2SE 7.0,作为二进制数,使用形式0B(或0B),接着通过一个或多个二进制位(0或1)。例如,0b101010是整数42.像八进制和十六进制数字,二进制文字可能会重新present负数。

4) Starting in J2SE 7.0, as binary numbers, using the form 0b (or 0B) followed by one or more binary digits (0 or 1). For example, 0b101010 is the integer 42. Like octal and hex numbers, binary literals may represent negative numbers.

如果你没有J2SE 7.0使用本:

If you do not have J2SE 7.0 use this:

int val = Integer.parseInt("001101", 2);

这篇关于在Java中有二进制文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 08:08