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?
Hexa = 0x and binary = ??
- floodhound2
- ∑lectronic counselor
- Posts: 2117
- Joined: 03 Sep 2006, 16:00
- 17
- Location: 127.0.0.1
- Contact:
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;
}
₣£ΘΘĐĦΘŮŇĐ
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".
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 =)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".
Anyway, thanks both of you for the answers ^^