Hexa = 0x and binary = ??

Stuff that don´t fit in the other categories.
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Hexa = 0x and binary = ??

Post by ayu »

Hexa uses the prefix 0x in C++ for example to indicate that it indeed is a hexadecimal number.

But what about binary numbers?

What prefix does binary use? :?

User avatar
floodhound2
∑lectronic counselor
∑lectronic counselor
Posts: 2117
Joined: 03 Sep 2006, 16:00
17
Location: 127.0.0.1
Contact:

Post by floodhound2 »

is it [ %b ] that is typical but i am not sure with C++ and your compiler.

Code: Select all

int main (int argc, char *argv[])
{
char buf[500];
int index = 499;
buf[index] = '\0';
int n;
n = -275;

int neg;
neg = 0;
if(n < 0) {
neg = 1;
n *= -1;
}

do {
int d;
d = n % 2;
buf[--index] = (char)(d + '0');

n = n >> 1;
} while( n > 0);

if(neg) {
buf[--index] = '-';
}

printf("%s\n", &buf[index]);
return 0;
}
₣£ΘΘĐĦΘŮŇĐ

G-Brain
Fame ! Where are the chicks?!
Fame ! Where are the chicks?!
Posts: 467
Joined: 08 Nov 2007, 17:00
16
Location: NL

Post by G-Brain »

There is no standard syntax for binary numbers. This macro by Tom Torfs can help you with that though:

http://groups.google.com/group/comp.arc ... 6d3da12c8f

Pretty ingenious.

Hexadecimal in short is "hex" by the way, not "hexa".

User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

Post by ayu »

G-Brain wrote:There is no standard syntax for binary numbers. This macro by Tom Torfs can help you with that though:

http://groups.google.com/group/comp.arc ... 6d3da12c8f

Pretty ingenious.

Hexadecimal in short is "hex" by the way, not "hexa".
Well I'm Swedish, and have always used 'Hexa', and will continue to do so =)

Anyway, thanks both of you for the answers ^^

Post Reply