Short类型在计算机中的存储

来源:互联网 发布:错生网络剧1 20集资源 编辑:程序博客网 时间:2024/04/29 03:21
package com.hnzhrh.Chapter4;import java.util.*;public class Bit {public static void main(String[] args) {// TODO Auto-generated method stub//创建一个数组存储各个位的值int a[]= new int[32];short flag=1;System.out.println("Please enter an short integer : ");Scanner input = new Scanner( System.in);short num=input.nextShort();int i=0;while((flag!=(short)0)){a[i++]=num&1;num >>=1;flag=(short)(flag<<1);}for(i=15;i>=0;i--){System.out.print(a[i] + " ");}input.close();}}

0 0
原创粉丝点击