2014世界杯决赛_国足进过世界杯吗 - hntink.com

Java 中的字节(Byte)和位(Bit)以及基本数据类型各占多少字节

一、字节(Byte)和位(Bit)

1、Java 中的字节容量关系

1 GB = 1024 MB,GB:千兆

1 MB = 1024 KB,MB:兆

1 KB = 1024 B,KB:千字节,B 是 Byte 的缩写,即字节。

2、字节(Byte)和位(Bit)的关系

(1)Bit——Binary Digit(二进制数位)的缩写,叫作“位”或“比特”,是计算机运算的基础。Bit 代表二进制数位,取值范围为:0 或 1。

(2)Byte——叫作“字节”,是计算机文件大小的基本计算单位。

(3)两者关系:1 Byte = 8 Bit。

二、基本数据类型各占多少字节

基本数据类型类型字节数位数取值范围boolean布尔型18true / falsechar字符型216采用unicode编码,字符的存储范围在\u0000~\uFFFFbyte整型18-128~127(−27-2^7−27 ~ 27−12^7 - 127−1)short整型216-32768~32767(−215-2^{15}−215 ~ 215−12^{15} - 1215−1)int整型432−231-2^{31}−231 ~ 231−12^{31} - 1231−1long整型864−263-2^{63}−263 ~ 263−12^{63} - 1263−1float浮点型432[−3.40282346638528860×1038-3.40282346638528860 \times 10^{38}−3.40282346638528860×1038 , −1.40129846432481707×10−45-1.40129846432481707 \times 10^{-45}−1.40129846432481707×10−45] ∪ [1.40129846432481707×10−451.40129846432481707 \times 10^{-45}1.40129846432481707×10−45 ~ 3.40282346638528860×10383.40282346638528860 \times 10^{38}3.40282346638528860×1038]double浮点型864[−1.79769313486231570×10308-1.79769313486231570 \times 10^{308}−1.79769313486231570×10308,−4.94065645841246544×10−324-4.94065645841246544 \times 10^{-324}−4.94065645841246544×10−324] ∪ [4.94065645841246544×10−3244.94065645841246544 \times 10^{-324}4.94065645841246544×10−324,1.79769313486231570×103081.79769313486231570 \times 10^{308}1.79769313486231570×10308]三、将 int 类型数据转换为其它进制并打印

将 int 或 byte 数据转换成 2 进制、8 进制或 16 进制,转换成字符串的形式打印。

1、int 类型转换成 2 进制打印:

int i = 24;

String s1 = Integer.toBinaryString(i);

System.out.println(s1);

测试结果:

11000

2、int 类型转换成 8 进制打印:

int i = 24;

String s2 = Integer.toOctalString(i);

System.out.println(s2);

测试结果:

30

3、int 类型转换成 16 进制打印:

int i = 24;

String s3 = Integer.toHexString(i);

System.out.println(s3);

测试结果:

18

电脑系统日志保存多长
合肥惠科金扬工资待遇怎么样?薪资福利如何?
2025-08-17 04:33:24

友情链接