Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Basic ?: Binary Digits in C/C++

Basic ?: Binary Digits in C/C++
Thread Tools
Junior Member
Join Date: Oct 2001
Location: Los Angeles
Status: Offline
Reply With Quote
Feb 21, 2002, 01:23 AM
 
I pose a simple question: Is there a way to code binary digits into a program rather than typical decimal.

I know this is possible with hex and oct, but I can't find any information about binary.

I want something like this: 0xA only for binary-- not hex.

I thought this should be something easy to do, but I can't find mention of such a feature in any of my books. I thought I would try you guys out.
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Eastern Washington (St. John/Cheney)
Status: Offline
Reply With Quote
Feb 21, 2002, 02:14 AM
 
Originally posted by Arakageeta256:
<STRONG>I pose a simple question: Is there a way to code binary digits into a program rather than typical decimal.

I know this is possible with hex and oct, but I can't find any information about binary.

I want something like this: 0xA only for binary-- not hex.

I thought this should be something easy to do, but I can't find mention of such a feature in any of my books. I thought I would try you guys out.</STRONG>
Woah...I could have sworn there is a way to do this in C++. But after checking my reference manual, I can't find any mention of this. I though it was something like this
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>int foo = 010101010b;</font>[/code]

Note the 'b' at the end. Strange. Just tested it in Project Builder and it didn't work. Guess it's not possible to do that. Apparently nobody uses binary anymore :-)

CyberDave
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Feb 21, 2002, 06:27 AM
 
!

Same here, I knew it was either 0b1010101010 or 1010101010b.

But it seems to have disappeared (won't compile). I *know* I used binary constants before...
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Feb 21, 2002, 09:21 AM
 
Come to think of it, the last time I used binary constants was in VirtualPC using TIGCC (compiler for TI calculators) for coding sprites. I'm not sure if I ever used it on cc.
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status: Offline
Reply With Quote
Feb 21, 2002, 12:45 PM
 
There is no language construct for binary in C/C++ (it would be 0b01010101 if there was). However, hex is very suitable to any thing you'd want to cade as binary since hex is really just shorthand for binary. I use hex all the time for bit masking.
     
Junior Member
Join Date: Oct 2001
Location: Los Angeles
Status: Offline
Reply With Quote
Feb 21, 2002, 06:25 PM
 
C/C++ supports almost every assbackward way of doing things. It's amazing that this isn't. Oh well, I guess hex will do fine.
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 12:08 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2