From: Joseph Rose 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 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Or x & (1< On Sun, 30 Apr 2000 16:09:53 -0400, Joseph Rose > 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/