| | |
hexadecimal to decimal
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 14
Reputation:
Solved Threads: 0
Hi I want to write a program which reads a hexadecimal number and returns an decimal number.
I wrote that code(inspired by some code pieces from web):
but it does't give the answer I want
I want to get 16 for 10000000 or 1109651713 for 01F12342 .
Could you please help me with that?
Thanks
--
newbiecoder
I wrote that code(inspired by some code pieces from web):
C Syntax (Toggle Plain Text)
#include <stdio.h> int main() { int hexa; scanf("%x", &hexa); printf("%d", hexa); return 0; }
but it does't give the answer I want
I want to get 16 for 10000000 or 1109651713 for 01F12342 .
Could you please help me with that?
Thanks
--
newbiecoder
> Use the itoa function / sprintf function if you want to convert decimal to hexadecimal (I'm not sure about the fact that the sprintf function will convert a string containing a decimal number to a hexadecimal number, you can simply test it if you want to know it
) ...
> If you don't care about the fact the code is in C/C++ you can also check out this code snippet
) ...> If you don't care about the fact the code is in C/C++ you can also check out this code snippet
Last edited by tux4life; Apr 26th, 2009 at 7:39 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
•
•
•
•
Although itoa function seems very useful, I couldn't use it, I use Ubuntu and gcc compiler. And when I try to compile I get this error:
What is the problem you think?
Thanks
#include <stdlib.h> "Never argue with idiots, they just drag you down to their level and then beat you with experience."
1: Zero your Total
2: Read the input as a string (hex)
3: Check each character and conve rt it into decimal value (A=10, B=11, etc)
4: Multiply Total by 16 and add the above value
5: Back to 2
2: Read the input as a string (hex)
3: Check each character and conve rt it into decimal value (A=10, B=11, etc)
4: Multiply Total by 16 and add the above value
5: Back to 2
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- decimal to hexadecimal (C#)
- NEED HELP! (hex to decimal output) (Assembly)
- hexadecimal convertions (C#)
- reading a hexadecimal number (C++)
- Decimal to hex conversion with recursion (Java)
- hexadecimal.cpp (C++)
- help with programming (C++)
- hop over decimal and straight to business (C++)
- decimal > binary > Oct > Hex (C++)
Other Threads in the C Forum
- Previous Thread: Get Error 'hWndDlg' undeclared(first use this function)..
- Next Thread: Numbers to words
Views: 1655 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C
adobe ansi api array arrays bash binarysearch centimeter char convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory drawing dynamic executable fflush file floatingpointvalidation fork frequency getlasterror getlogicaldrivestrin givemetehcodez global graphics gtkgcurlcompiling hardware highest homework i/o ide inches infiniteloop initialization interest kilometer lazy linked linkedlist linux linuxsegmentationfault list logical_drives match matrix meter microsoft motherboard multi mysql open opendocumentformat openwebfoundation pattern pause pdf pointer pointers posix power problem program programming pyramidusingturboccodes read recursion recv repetition scanf scheduling segmentationfault send shape single socketprograming socketprogramming spoonfeeding stack standard strchr string strings structures student suggestions system test testautomation unix urboc user voidmain() win32 win32api windows.h






