Hi all,
Is there any sample program for converting Binary number to Decimal number in C..
I can find program in C++ only...
Thanks in advance,
xiao guang
Printable View
Hi all,
Is there any sample program for converting Binary number to Decimal number in C..
I can find program in C++ only...
Thanks in advance,
xiao guang
Have you tried understanding the C++ code and then writing your own program?
I'm assuming you want to convert an integer like 110011 to decimal?
Find out how to deal with each digit seperately, then add it back with a power of 2 instead of 10.
>>Binary number
Can you confirm your meaning of this term. What variable type are you converting from?
Binary and Decimal are the same thing-- simply different representations. You didn't ask for text conversions, Reclaimer, so that isn't discussed in this index.
Since binary is base-2, it's very easy.
1) What is your value-size? long, short, byte?
2) Create a mask for the high-bit
3) test the value against that mask to determine value of set/cleared bit.
4) right-shift the mask by one, and go back to step 3 until all bits tested
5) convert resulting value to a string (if that's what you want) and display as decimal.
If you're just using string conversions, then use the string library.
Ah, I must go. The Flood have breached a plasma conduit on level 6 so I must reenergize the drone subsystem.