Velocity Reviews > How to calculate size of an int without using the sizeof operator but using bitwise operator

# How to calculate size of an int without using the sizeof operator but using bitwise operator

Keith Thompson
Guest
Posts: n/a

 02-13-2005
Eric Sosman <(E-Mail Removed)> writes:
> Clark S. Cox III wrote:
>
>> On 2005-02-12 04:25:55 -0500, Gregory Toomey <(E-Mail Removed)> said:
>>
>>> Manish_Ganvir wrote:
>>>
>>>> Please do not use pointer arithmetic or for loops
>>>> Solution
>>>
>>>
>>> Set an unsigned int to 1, use the left shift operator << , test
>>> whether its
>>> zero.

>>
>>
>> That won't always work (think padding-bits, trap representations, etc.).

>
> Not applicable. The shift operator works with
> the values of its operands, not with their representation.

Right, and the question was about the representation, specifically the
size.

If you have a 32-bit integer type with 8 padding bits, any solution
using bitwise operations will tell you it has 24 bits. The question
was about its size, 32 bits, not its width.

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Manish_Ganvir
Guest
Posts: n/a

 02-14-2005
It is a nice way to say that you dont know the solution, i really

Thanks

CBFalconer
Guest
Posts: n/a

 02-14-2005
Manish_Ganvir wrote:
>
> It is a nice way to say that you dont know the solution, i really

No quotes again. What does 'it' refer to? Solution to what? I
suspect that 'it' is really a toned down version of "stop wasting
our time".

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the

Keith Thompson
Guest
Posts: n/a

 02-14-2005
"Manish_Ganvir" <(E-Mail Removed)> writes:
> It is a nice way to say that you dont know the solution, i really

Following the References header indicates that this was a followup to
my article, but you didn't provide any context.

If you want to post a followup via groups.google.com, don't use the
broken "Reply" link at the bottom of the article. Click on "show
options" at the top of the article, then click on the "Reply" at the

Most of us either know a solution, or could figure one out if we spent
the time on it, or (depending on how your question is interpreted)
could demonstrate that no solution is possible. We simply aren't
interested in doing your homework for you.

If you have some valid reason for this rather odd question other than
a homework assignment, I'm sure many of us would be glad to help.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.