PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > Finding number of bits of integer
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
Finding number of bits of integer

Réponse
 
LinkBack Outils de la discussion
Vieux 20/10/2007, 13h47   #26
Army1987
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding number of bits of integer

On Thu, 18 Oct 2007 18:44:05 -0400, pete wrote:

> Richard Heathfield wrote:
>> int count_value_bits_in_unsigned_int(void)
>> {
>> int rv = 0;
>> unsigned int n = UINT_MAX;
>> while(n > 0)
>> {
>> ++rv;
>> n >>= 1;
>> }
>> return rv;
>> }

>
> rv should be type unsigned, instead of type int.
> The number of value bits in type unsigned isn't
> guaranteed to be representable as an int type value.

That'd require one unsigned int to occupy at least 4 KB
--
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.

  Réponse avec citation
Vieux 20/10/2007, 14h06   #27
Army1987
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding number of bits of integer

On Thu, 18 Oct 2007 18:44:05 -0400, pete wrote:

> The number of value bits in type unsigned isn't
> guaranteed to be representable as an int type value.


Finding the greatest lower bound for the fraction of padding bits
among the bits of int on any implementation where log2(UINT_MAX+1.0)
is greater than INT_MAX is left as an exercise to the reader.

Now an implementation which wastes more than 99.5% (Hint: unless
I had something wrong, this is strictly less than the greatest
lower bound) of the bits in an int is an implementation I would
rather never have *anything* to do with (including "being to
within one light-year of each other").
--
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.

  Réponse avec citation
Vieux 20/10/2007, 14h11   #28
Charlie Gordon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding number of bits of integer

"Army1987" <army1987@NOSPAM.it> a écrit dans le message de news:
pan.2007.10.20.12.47.07.181515@NOSPAM.it...
> On Thu, 18 Oct 2007 18:44:05 -0400, pete wrote:
>
>> Richard Heathfield wrote:
>>> int count_value_bits_in_unsigned_int(void)
>>> {
>>> int rv = 0;
>>> unsigned int n = UINT_MAX;
>>> while(n > 0)
>>> {
>>> ++rv;
>>> n >>= 1;
>>> }
>>> return rv;
>>> }

>>
>> rv should be type unsigned, instead of type int.
>> The number of value bits in type unsigned isn't
>> guaranteed to be representable as an int type value.

> That'd require one unsigned int to occupy at least 4 KB


And the corresponding int representation to have at least 16368 padding bits
;-)

--
Chqrlie.


  Réponse avec citation
Vieux 21/10/2007, 09h54   #29
Army1987
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding number of bits of integer

On Sat, 20 Oct 2007 15:11:26 +0200, Charlie Gordon wrote:

> "Army1987" <army1987@NOSPAM.it> a écrit dans le message de news:
> pan.2007.10.20.12.47.07.181515@NOSPAM.it...
>> On Thu, 18 Oct 2007 18:44:05 -0400, pete wrote:
>>> rv should be type unsigned, instead of type int.
>>> The number of value bits in type unsigned isn't
>>> guaranteed to be representable as an int type value.

>> That'd require one unsigned int to occupy at least 4 KB

>
> And the corresponding int representation to have at least 16368 padding bits
> ;-)


Have you found a way for such an implementation to have less than
32752 padding bits in int?
(Yes, "at least 16368" is still true if the greatest lower bound
is 32752, but I wander if you found that that lower bound is
wrong.)
--
Army1987 (Replace "NOSPAM" with "email")
A hamburger is better than nothing.
Nothing is better than eternal happiness.
Therefore, a hamburger is better than eternal happiness.

  Réponse avec citation
Vieux 25/10/2007, 14h14   #30
Charlie Gordon
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Finding number of bits of integer

"Army1987" <army1987@NOSPAM.it> a écrit dans le message de news:
pan.2007.10.21.08.54.53.234455@NOSPAM.it...
> On Sat, 20 Oct 2007 15:11:26 +0200, Charlie Gordon wrote:
>
>> "Army1987" <army1987@NOSPAM.it> a écrit dans le message de news:
>> pan.2007.10.20.12.47.07.181515@NOSPAM.it...
>>> On Thu, 18 Oct 2007 18:44:05 -0400, pete wrote:
>>>> rv should be type unsigned, instead of type int.
>>>> The number of value bits in type unsigned isn't
>>>> guaranteed to be representable as an int type value.
>>> That'd require one unsigned int to occupy at least 4 KB

>>
>> And the corresponding int representation to have at least 16368 padding
>> bits
>> ;-)

>
> Have you found a way for such an implementation to have less than
> 32752 padding bits in int?
> (Yes, "at least 16368" is still true if the greatest lower bound
> is 32752, but I wander if you found that that lower bound is
> wrong.)


No, your lower bound seems good.

--
Chqrlie.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 05h05.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,15726 seconds with 13 queries