Mail Archives: djgpp/2000/05/01/19:13:34
Or x & (1<<n), which can easily be converted to a constant equation
(1<<4=0x10) for quicker testing. But I meant writing a number in binary,
not testing or retrieving a few bits.
Damian Yerrick wrote:
> On Sun, 30 Apr 2000 16:09:53 -0400, Joseph Rose <jorose AT pop DOT gis DOT net>
> wrote:
>
> >Binary Numbers
> >How do I represent them in C++?
>
> On most platforms (including DJGPP):
>
> int x;
>
> You can retrieve bit n of integer x by doing this:
>
> foo = (x >> n) & 1;
>
> If you want to print the binary number, you can loop from n = 31 to 0
> to display the number in base 2, or you can use good old itoa().
>
> By "most platforms" I mean the ones that use binary arithmetic for
> objects of type `int'. I challenge comp.os.msdos.djgpp to find an
> important computer platform that does not.
>
> --
> Damian Yerrick
> "I refuse to listen to those who refuse to listen to reason."
> See the whole sig: http://www.rose-hulman.edu/~yerricde/sig.html
>
> This is McAfee VirusScan. Add these two lines to your signature to
> prevent the spread of signature viruses. http://www.mcafee.com/
- Raw text -