java字节数据类型 [英] java byte data type

查看:117
本文介绍了java字节数据类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Sun'教程中它说的是一个字节:

In Sun' tutorial it says about a byte:


byte:字节数据类型是一个8位带符号的二进制补码整数。它的最小值为-128,最大值为127(含)。字节数据类型可用于在大型阵列中保存内存,其中节省的内存实际上很重要。它们也可用于代替int,其限制有助于澄清您的代码;变量范围有限的事实可以作为一种文档形式。

byte: The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.

它如何节省内存?什么是2的赞美?

How does it save memory? What is 2's compliment?

推荐答案

它通过仅消耗8位存储来节省内存,而整数则为32。数组的大小与包含的数据类型的大小成正比;一个整数数组将消耗大约四倍于内存数据的内存( handwaves )。

It saves memory by consuming only eight bits of storage, versus 32 for integers. The size of arrays is directly proportional to the size of the contained datatype; an array of integers will consume about four times more memory (handwaves) than an array of bytes.

来自维基百科


一个两个-complement system或
二进制补码算法是一个
系统,其中负数是
,由
的二进制补码表示绝对值; 1 这个系统是
在计算机上代表
签名整数的最常用方法。[2]在
这样的系统中,通过计算其两个
补充,一个数字被否定
(从正数转换为负数b $ b,反之亦然)。 N位二进制补码
数字系统可以表示-2 ^(N-1)到
+ 2 ^(N-1)-1范围内的每个
整数。

A two's-complement system or two's-complement arithmetic is a system in which negative numbers are represented by the two's complement of the absolute value;1 this system is the most common method of representing signed integers on computers.[2] In such a system, a number is negated (converted from positive to negative or vice versa) by computing its two's complement. An N-bit two's-complement numeral system can represent every integer in the range −2^(N−1) to +2^(N−1)−1.

这篇关于java字节数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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