我们如何用Java编写浮点数的二进制,八进制和十六进制文字? [英] How we can write binary, octal and hexadecimal literals of floating point numbers in Java?

查看:59
本文介绍了我们如何用Java编写浮点数的二进制,八进制和十六进制文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何用Java编写浮点数的二进制,八进制和十六进制文字?无论是科学的还是正常的代表.

How we can write binary, octal and hexadecimal literals of floating point numbers in Java? Either in scientific or in normal representation.

class First
{
        public static void main(String[] args)
        {
                double b = 0x12p3;
                System.out.println(b);
        }
}

以上程序结果为144.0

The above program results 144.0

class First
{
        public static void main(String[] args)
        {
                double b = 0x12e3;
                System.out.println(b);
        }
}

以上程序结果为4835.0

The above program results 4835.0

class First
{
            public static void main(String[] args)
            {
                    double b = 0x12e3;
                    System.out.println(b);
            }
}

以上程序结果为4835.0

The above program results 4835.0

class First
{
            public static void main(String[] args)
            {
                    double b = 012e3;
                    System.out.println(b);
            }
}

上述计划的结果为12000

The above program results 12000

请解释以上输出.

推荐答案

第一个示例是HexadecimalFloatingPointLiteral,(16 + 2)* 8 = 144.

The first example is a HexadecimalFloatingPointLiteral, (16+2)*8 = 144.

第二个和第三个示例实际上是分配给双变量1 * 16 * 16 * 16 + 2 * 16 * 16 + 14 * 16 + 3 = 4835的HexIntegerLiteral.请注意,"e"只是十六进制14位数字.

The second and third example is actually a HexIntegerLiteral assigned to a double variable, 1*16*16*16 + 2*16*16 + 14*16 + 3 = 4835. Note that the 'e' is just the hex digit for 14.

最后一个示例是12 * 1000的DecimalFloatingPointLiteral.

The last example is a DecimalFloatingPointLiteral, 12 * 1000.

Java不支持八进制浮点文字.

Java does not support an octal floating point literals.

有关所有详细信息,请参见JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.2

For all the details see the JLS: https://docs.oracle.com/javase/specs/jls/se8/html/jls-3.html#jls-3.10.2

这篇关于我们如何用Java编写浮点数的二进制,八进制和十六进制文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆