[Resolved] binary numbers

Write here if you have problems with your C++ source code

Moderator: Board moderators

Post Reply
bugzpodder
Experienced poster
Posts: 147
Joined: Fri Jun 13, 2003 10:46 pm

[Resolved] binary numbers

Post by bugzpodder »

is there a way to represent binary # in C++? something like this: 0xff to represent FF in hex, can you do the same for binary?
Last edited by bugzpodder on Mon Aug 23, 2004 8:21 pm, edited 1 time in total.
Viktoras Jucikas
New poster
Posts: 22
Joined: Sun Oct 20, 2002 6:41 pm
Location: Lithuania
Contact:

Post by Viktoras Jucikas »

You can't do this.
Julien Cornebise
Experienced poster
Posts: 145
Joined: Sat Feb 23, 2002 2:00 am
Location: Paris, France
Contact:

Post by Julien Cornebise »

You can't, but keep in mind that it is simple to come from hexa to binary and vice versa : hexa digits are only groups of 4 binary digits.
bery olivier
Learning poster
Posts: 90
Joined: Sat Feb 15, 2003 1:39 am
Location: Paris, France
Contact:

Post by bery olivier »

You can use the '&' operator as well

[c]#include<stdio.h>

void print(long bin)
{
if(bin>1)
print(bin>>1);
putchar((bin&1)+'0');
}


int main(void)
{
long bin;
scanf("%ld",&bin);
while(bin)
{
print(bin);
putchar('\n');
scanf("%ld",&bin);
}
return 0;
}[/c][/quote]
Not AC yet Image AC at last Image
Post Reply

Return to “C++”