in a book i saw that there is function built into c that displays the binary value of a number, it looks something link this
showbits(int);
but when i tried it, didnt work, do you know which header file i have to include to enable this?
in a book i saw that there is function built into c that displays the binary value of a number, it looks something link this
showbits(int);
but when i tried it, didnt work, do you know which header file i have to include to enable this?
I have never heard of this function 'showbits', but from its name and the sintax I believe that there might be a workaround, or another function that does the same thing as this function. I know that the function '_itoa(string, number, base)' in MSVC++ 6, can be used to display the binary value of a integer in a string. I don't know if this will work in other compliers but here is an example of the usage of _atoi for MSVC++.
The output is as follows.Code:#include <cstdlib> #include <iostream> using std::cin; using std::cout; using std::endl; int main() { char buffer[20]; int i = 3445; _itoa( i, buffer, 10 ); cout << "String of integer " << i << " (radix 10): " << buffer << endl; _itoa( i, buffer, 16 ); cout << "String of integer " << i << " (radix 16): " << buffer << endl; _itoa( i, buffer, 2 ); cout << "String of integer " << i << " (radix 2): " << buffer << endl; return 0; }
-JLBsheckyCode:String of integer 3445 (radix 10): 3445 String of integer 3445 (radix 16): d75 String of integer 3445 (radix 2): 110101110101
System
OS - Microsoft Windows XP Pro
CPU - AMD Athlon XP 2600+
Mother Board - Abit KV7
RAM - 512 Mb DDR (333)
C++
Microsoft Visual Studio Pro. 6.0
MSDN July 2001
Which might be fine if they were using C++. However, this is the C board.Originally posted by JLBSchreck
I know that the function '_itoa(string, number, base)' in MSVC++ 6, can be used to display the binary value of a integer in a string. I don't know if this will work in other compliers but here is an example of the usage of _atoi for MSVC++.
-JLBsheckyCode:snip c++ code
Quzah.
Hope is the first step on the road to disappointment.
Replace all cout statements with fitting printf statements and there you are. _itoa is plain C.Originally posted by quzah
Which might be fine if they were using C++. However, this is the C board.
Quzah.
But this is the cross-platform C forum, not the MS forum
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law
Not really. _itoa is Microsoft. the underscore is the clue. Just this alone tells me that itoa() is not a standard function.Originally posted by CornedBee
Replace all cout statements with fitting printf statements and there you are. _itoa is plain C.
ANSI C only defines ato?() functions, not the other way around. MS usually puts an underscore in front of functions that are not ANSI Standard, whereas Borland does not.
Many compilers though have defined ?toa() functions, but you can't rely on them for portability.
Definition: Politics -- Latin, from
poly meaning many and
tics meaning blood sucking parasites
-- Tom Smothers
Plain C != Standard C.Not really.
This is why I posted this part:
But this is the cross-platform C forum, not the MS forum.
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law