ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

java数据类型--整型

2022-04-10 18:32:37  阅读:147  来源: 互联网

标签:short java -- 数据类型 System int println Integer out


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:整型中按字节反转,不是按位反转。

 

标签:short,java,--,数据类型,System,int,println,Integer,out
来源: https://www.cnblogs.com/bianguji/p/16126696.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有