Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

This is what I read about a byte on the sun’s official website. 

“ 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.”

 

How byte saves memory?  And What’s 2’s complement?

1 Answer

0 votes
by (19.7k points)

Byte saves memory compared to the other data types. It takes up only 8 bits of storage. The size of the array is directly proportional to the data type size. So an array of bytes consumes less memory. 

2’s complement :

It is the representation of negative numbers in their 2’s complement. computers use 2’s complement to represent signed integers. You can easily convert a number from positive to negative or vice versa with  2’s complement. It helps to represent every integer in the range −2^(N−1) to +2^(N−1)−1. 

Interested in Java? Check out this Java tutorial by Intellipaat.

Related questions

0 votes
1 answer
asked Mar 14, 2021 in Java by Jake (7k points)
0 votes
1 answer
asked Feb 18, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
asked Feb 4, 2021 in Java by dev_sk2311 (45k points)

Browse Categories

...