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

I googled bit depth, it is the number of bits used to store information about each pixel in a computer image, I wouldn't worry to much about it terms of Java

Vasco Dion�sio
Greenhorn

Joined: Dec 04, 2003
Posts: 22

posted

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

Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326

posted

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 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'.

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 ]

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.

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 ]