# Bit depth - What does it really means?

Vasco Dion�sio

Greenhorn

Posts: 22

posted 12 years ago

- 0

Could someone explain to me what exactly does the concept of "Bit Depth" means?

For instance:

A primitive type "char" has 16 bit (unsigned) so I can use 2^16 possible combinations (65536);

if a "byte" has 8 bits (signed) it means the first bit indicates if the value is positive or negative, right? So, I get 7 bits to the absolute numerical value. What is the bit depth of a "byte"? 7 or 8?

Thanks a lot...

For instance:

A primitive type "char" has 16 bit (unsigned) so I can use 2^16 possible combinations (65536);

if a "byte" has 8 bits (signed) it means the first bit indicates if the value is positive or negative, right? So, I get 7 bits to the absolute numerical value. What is the bit depth of a "byte"? 7 or 8?

Thanks a lot...

Ray Stojonic

Ranch Hand

Posts: 326

Vasco Dion�sio

Greenhorn

Posts: 22

posted 12 years ago

- 0

First off all thanks for your answer...

Neverthless, I think that's only one of the meanings of the expression, because I believe it also means the number of bits available for computing the range of numerical combinations in a primitive type in Java, am I right?

My question concerns more with the last meaning...

Thanks anyway for your help...

Neverthless, I think that's only one of the meanings of the expression, because I believe it also means the number of bits available for computing the range of numerical combinations in a primitive type in Java, am I right?

My question concerns more with the last meaning...

Thanks anyway for your help...

Ray Stojonic

Ranch Hand

Posts: 326

posted 12 years ago

- 0

hmmm

(more googling)

.

.

.

A quick scan of the results tells me that 99% of the time, bit depth refers to number of bits used to describe a pixel.

However, the one exception I found refered to bit depth as the size of a container, in bits; which makes sense, given the first explanation.

So, you

(more googling)

.

.

.

A quick scan of the results tells me that 99% of the time, bit depth refers to number of bits used to describe a pixel.

However, the one exception I found refered to bit depth as the size of a container, in bits; which makes sense, given the first explanation.

So, you

*could*say that the bit depth of a byte is 8, but I think people will understand you better if you stick with the tried and true: 'a byte is 8 bits'.
Ben McElyea

Greenhorn

Posts: 1

posted 12 years ago

- 0

There are 8 bits to a byte. A byte has 256 possible values

a bit is a 1 or 0.

To convert from decimal to binary you just "turn on" one of the zeros

So a byte with the value of 00000001 is 1, 00000011 is 2, 00000100 is 4,

01100000 is 64+32 = 96 , 11111111 would be 128+64+32+16+8+4+2+1 = 255. When it is signed the bit at the decimal 128 place is used to either show positive or negative. So the max value a signed byte can have is 127:

011111111 or 64+32+16+8+4+2+1 = 127

111111111 or 64+32+16+8+4+2+1 = -127

[ December 19, 2003: Message edited by: Ben McElyea ]

a bit is a 1 or 0.

To convert from decimal to binary you just "turn on" one of the zeros

So a byte with the value of 00000001 is 1, 00000011 is 2, 00000100 is 4,

01100000 is 64+32 = 96 , 11111111 would be 128+64+32+16+8+4+2+1 = 255. When it is signed the bit at the decimal 128 place is used to either show positive or negative. So the max value a signed byte can have is 127:

011111111 or 64+32+16+8+4+2+1 = 127

111111111 or 64+32+16+8+4+2+1 = -127

[ December 19, 2003: Message edited by: Ben McElyea ]

Michael Sullivan

Ranch Hand

Posts: 235

posted 12 years ago

- 0

While reviewing the Osbourne Java2 SCJP/ SCJD book, bit depth refers the not only the number if bits in each primitive, but also the range of values that you might expect. For instance:

literal ranges for the exam. To calculate the range of a number, you use the following formula

-2 to the power of (bits-1) = negative range

2 to the power of (bits-1)-1 = positive range

the positive is one less than the negative because the zero is stored as a positve binary number.

TYPE.....BITS.....BYTES.....Possibilites

byte.....8........1.........256

short....16.......2.........> 60,000

int......32.......4.........> 4 billion

long.....64.......8

float....32.......4.........> 60,000

double...64.......4

Where I see this mostly tested (in the osbourne book) is when the code tries to implicitly cast into another type... so if you know that a char is really a 16bit unsigned integer, you know that it can be implicitly cast into int.

[ December 26, 2003: Message edited by: Michael Sullivan ]

[ December 26, 2003: Message edited by: Michael Sullivan ]

literal ranges for the exam. To calculate the range of a number, you use the following formula

-2 to the power of (bits-1) = negative range

2 to the power of (bits-1)-1 = positive range

the positive is one less than the negative because the zero is stored as a positve binary number.

TYPE.....BITS.....BYTES.....Possibilites

byte.....8........1.........256

short....16.......2.........> 60,000

int......32.......4.........> 4 billion

long.....64.......8

float....32.......4.........> 60,000

double...64.......4

Where I see this mostly tested (in the osbourne book) is when the code tries to implicitly cast into another type... so if you know that a char is really a 16bit unsigned integer, you know that it can be implicitly cast into int.

[ December 26, 2003: Message edited by: Michael Sullivan ]

[ December 26, 2003: Message edited by: Michael Sullivan ]

It is sorta covered in the JavaRanch Style Guide. |