www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/05/01/19:13:34

From: Joseph Rose <jorose AT mail DOT gis DOT net>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Binary Numbers
Date: Mon, 01 May 2000 19:45:46 -0400
Organization: Posted via Supernews, http://www.supernews.com
Lines: 35
Message-ID: <390E1729.4C3C27DE@pop.gis.net>
References: <390C9311 DOT E12D0FB3 AT pop DOT gis DOT net> <7j2sgs0nnetaqqdd5i60qk8nn9p1mmsrg1 AT 4ax DOT com>
X-Complaints-To: newsabuse AT supernews DOT com
X-Mailer: Mozilla 4.7 [en]C-NECCK (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019