RJ said:
Sorry for the confusion. Its a double* p.
First of all, the fact that it's a pointer (whether of type double* or
unsigned long* or whatever) is irrelevant based on what you say below.
You seem to care about the pointee, not the pointer.
In the case of doubles, the floating point format is
implementation-dependent. There are a certain number of bits allocated
for the exponent and a certain number for the mantissa, but those
numbers are not standard. Check your platform documentation for the
floating point format.
For example,
unsigned long* lp=0xFFF;
if I have RGB value in *lp and the RGB is 444 format. Only 12 bits are
used out of 32 bit. Remaining 20 bits padded with 0.
unsigned long* lp=0xFFFFFF;
Like if i have RGB of 888, then only 24 bit used and remaining 8 bits
padded with 0.
So my question is how to find a pointer content is used only 'n' number
of bytes and remaining 'm' number of bytes are padded to 0.
ie.,In generic how to calculate n and m?
As the other responder pointed out, you might get into trouble with
certain values, depending on how you use the number of non-zero bits.
Usually, in image processing applications, you just need to keep track
of how many bits are valid and only work on those. That means that you
may need to pass a mask or bit count (and perhaps other relevant
information) around to your functions along with the pixels, but that's
just part of the game.
In case you do have a legitimate use for such information, you can
easily calculate it:
unsigned CountBitsUsed( unsigned long val )
{
for( int n=sizeof(unsigned long)-1; n > 0; --n )
if( 0 != (val & (1<<n)) )
return n+1;
return 0;
}
Cheers! --M