Need program to print bits in data types in CUnread news in comp.lang.c 3982 articles +11329 old 
Author Message
 Need program to print bits in data types in CUnread news in comp.lang.c 3982 articles +11329 old

Could someone please send me a program that will print
the bits in the basic data types in C. I'd like to give
such a program to the students in my class.

Thanks

Mark Austin



Tue, 16 Jul 1996 07:24:40 GMT  
 Need program to print bits in data types in CUnread news in comp.lang.c 3982 articles +11329 old

Quote:

>Could someone please send me a program that will print
>the bits in the basic data types in C. I'd like to give
>such a program to the students in my class.

What a clever ruse for getting the answer to a homework problem!

Hint:  set an unsigned version of each integral type to all 1's,
then count the number of shifts it takes to end up with zero.

Floating types and pointers are harder.

Or you could figure out how many bits are in a char and calculate
sizeof(other type) * number-of-bits-in-a-char.

Dave Kristol



Wed, 17 Jul 1996 06:31:36 GMT  
 Need program to print bits in data types in CUnread news in comp.lang.c 3982 articles +11329 old


Quote:

> writes:

>Could someone please send me a program that will print
>the bits in the basic data types in C. I'd like to give
>such a program to the students in my class.

>Ummm... How bout:

>int main()
>{
>        printf ("%d bits in int\n",8*sizeof(int));
>        printf ("%d bits in long\n",8*sizeof(long));
>        printf ("%d bits in char\n",8*sizeof(char));
>        etc.
>}

sizeof(char) is defined to be 1 but a chars not guaranteed to be 8 bits.

#include <limits.h>

and use CHAR_BIT instead of 8.

-----------------------------------------


-----------------------------------------



Sat, 20 Jul 1996 01:05:48 GMT  
 Need program to print bits in data types in CUnread news in comp.lang.c 3982 articles +11329 old

Could someone please send me a program that will print
the bits in the basic data types in C. I'd like to give
such a program to the students in my class.

Ummm... How bout:

int main()
{
        printf ("%d bits in int\n",8*sizeof(int));
        printf ("%d bits in long\n",8*sizeof(long));
        printf ("%d bits in char\n",8*sizeof(char));
        etc.

Quote:
}

Or, did you mean something to convert the CONTENTS of variables of each type to binary?


Fri, 19 Jul 1996 22:52:59 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Correction to comp.lang.c news archives posting

2. news:comp.lang.c

3. c/c++ book, comp.lang.c++, comp.lang.c++.leda, comp.lang.c++.moderated, comp.lang.c.moderated, comp.sys.mac.programmer.codewarrior

4. NEWS:comp.lang.c.moderated

5. Newsgroups: comp.lang.c,comp.lang.c++,comp.lang.c++.moderated,comp.lang.c.moderated

6. Rogue Cancels in comp.lang.c and comp.lang.c++ originating from cnet.fr

7. Rogue Cancels in comp.lang.c and comp.lang.c++ originating from cnet.fr

8. comp.lang.prolog comp.lang.c

9. comp.lang.c/comp.lang.c++

10. Pre-RFD: comp.lang.c.advocacy and comp.lang.c.learn

11. CALL FOR DISCUSSION: comp.lang.c.dos and comp.lang.c.unix

12. RENAME comp.lang.c to COMP.LANG.ANSI.C

 

 
Powered by phpBB® Forum Software