Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

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 <> writes:
> Clark S. Cox III wrote:
>
>> On 2005-02-12 04:25:55 -0500, Gregory Toomey <> 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) kst- <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.
 
Reply With Quote
 
 
 
 
Manish_Ganvir
Guest
Posts: n/a
 
      02-14-2005
It is a nice way to say that you dont know the solution, i really
appreciate your effort guys

Thanks



 
Reply With Quote
 
 
 
 
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
> appreciate your effort guys


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
"Reply" at the bottom of the article headers." - Keith Thompson


 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      02-14-2005
"Manish_Ganvir" <> writes:
> It is a nice way to say that you dont know the solution, i really
> appreciate your effort guys


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
bottom of the article headers.

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) kst- <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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: sizeof(const int *) > sizeof(int *) Stargazer C Programming 14 07-08-2010 02:01 PM
Re: sizeof(const int *) > sizeof(int *) Ben Bacarisse C Programming 12 07-02-2010 04:10 AM
An implementation where sizeof(short int) does not divide sizeof(int) Spiros Bousbouras C Programming 40 01-20-2007 09:58 PM
dirty stuff: f(int,int) cast to f(struct{int,int}) Schnoffos C Programming 2 06-27-2003 03:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57