Java教程

java数据类型--整型

本文主要是介绍java数据类型--整型,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package cn.com.three.two.datatype;

import cn.com.util.formatStr;

/**
 * 整型数据类型
 * @author bianguji
 * @Since 2022年4月9日下午1:27:06
 */
public class IntegerType {
    public static void main(String[] args) {
        short s1=1;
        short s2=Short.MAX_VALUE;
        short s3=Short.MIN_VALUE;
        
        System.out.println("==========short=========");
        System.out.println(s1);
        System.out.println("short最大值:"+s2);
        System.out.println("short最小值:"+s3);
        System.out.println("short类型长度:"+Short.BYTES);
 
        System.out.println("0xA:"+Short.decode("0xA"));
        System.out.println("0XA:"+Short.decode("0XA"));
        System.out.println("#A:"+Short.decode("#A"));
        System.out.println("010:"+Short.decode("010"));
        
        
        System.out.println("反转:"+Short.reverseBytes((short)4));
        System.out.println("toUnsignedInt:"+Short.toUnsignedInt((short)-12));
        System.out.println("Bin:"+Integer.toBinaryString(65524));
        
        
        System.out.println("==========int=========");
        int i1=1;
        int i2=Integer.MAX_VALUE;
        int i3=Integer.MIN_VALUE;
        
        System.out.println(i1);
        System.out.println("int最大值:"+i2);
        System.out.println("int最小值:"+i3);
        System.out.println("int类型长度:"+Integer.BYTES);
 
        System.out.println("0xA:"+Integer.decode("0xA"));
        System.out.println("0XA:"+Integer.decode("0XA"));
        System.out.println("#A:"+Integer.decode("#A"));
        System.out.println("010:"+Integer.decode("010"));
        
        
        System.out.println("Bin:"+Integer.toBinaryString(10));
        System.out.println("Oct:"+Integer.toOctalString(10));
        System.out.println("Hex:"+Integer.toHexString(10));
        
        
        System.out.println("2to反转:"+Integer.reverseBytes(2));
        System.out.println("    2toBin:"+formatStr.formatSplit(formatStr.formatFill(Integer.toBinaryString(83), 32, "0"),8,"-"));
        System.out.println("2to反转Bin:"+formatStr.formatSplit(formatStr.formatFill(Integer.toBinaryString(Integer.reverseBytes(83)), 32, "0"),8,"-"));
    }
}

 

执行结果:

==========short=========
1
short最大值:32767
short最小值:-32768
short类型长度:2
0xA:10
0XA:10
#A:10
010:8
反转:1024
toUnsignedInt:65524
Bin:1111111111110100
==========int=========
1
int最大值:2147483647
int最小值:-2147483648
int类型长度:4
0xA:10
0XA:10
#A:10
010:8
Bin:1010
Oct:12
Hex:a
2to反转:33554432
    2toBin:00000000-00000000-00000000-01010011
2to反转Bin:01010011-00000000-00000000-00000000

 

toBinaryString:Integer转换二进制方法
toOctalString:Integer转换八进制方法
toHexString:Integer转换十六进制方法
toUnsignedInt:Short类转换无符号整型数据,short中的数值,补码,直接转入整型中。
reverseBytes:整型中按字节反转,不是按位反转。

 

这篇关于java数据类型--整型的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!