| | |
Accepting decimal value as hex value
![]() |
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Solved Threads: 0
hi friends,
This is my very 1st message on this site. Can someone please help me out in designing a small function in c programming to accept decimal value as hex value, i mean lets say if user inputs a decimal value say 49, the processor should read(and futher processes) it as 0x49(hex value).
Thanks .
With regards
This is my very 1st message on this site. Can someone please help me out in designing a small function in c programming to accept decimal value as hex value, i mean lets say if user inputs a decimal value say 49, the processor should read(and futher processes) it as 0x49(hex value).
Thanks .
With regards
•
•
Join Date: Apr 2007
Posts: 3
Reputation:
Solved Threads: 0
thanks for replying this bull shit Luckychap. First read properly what i have written then reply with your bull shit. I said i want to convert 49 decimal to 0x49 hex (or 1001001 in binary). normally proccessor would accept the 49 decimal value as 0x31 hex value. (or 110001 in binary).........Got it !!!!!!!!!!!!
do you want to convert to a string? sprintf() can do that.
C Syntax (Toggle Plain Text)
char hexval[8] = {0}; int n = 49; sprintf(hexval,"0x%X", n);
Last edited by Ancient Dragon; Apr 24th, 2007 at 12:14 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
I don't think C language is the best for your situation. With such small amount of memory you may need to use assembly. Depending on your compiler C's startup code can be fairly large.
Here is a thread that may help you.
Here is a thread that may help you.
Last edited by Ancient Dragon; Apr 24th, 2007 at 1:12 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Here is a solution -- taken from that link I provided
c Syntax (Toggle Plain Text)
char DecimalToHexa(int rem); void hexaDecimal(int h, char* buffer, int bufferSize); int main() { char buffer[8] = {0}; int deci=115; hexaDecimal(deci, buffer, sizeof(buffer)); printf("buffer = '%s'\n", buffer); return 0; } void hexaDecimal(int h, char * buffer, int bufferSize) { int rem; char output[8]= {0}; char digit = 0; int i = 0; int j = 0; int k = 0; do { rem = h%16; digit = DecimalToHexa(rem); h=h/16; output[i] = digit; ++i; } while(h/16!=0); if(h > 0) { rem = h; digit=DecimalToHexa(rem); output[i] = digit; ++i; } if(i >= bufferSize) { buffer[0] = 0; } else { for(j= i-1, k = 0; j >= 0; j--,k++) { buffer[k] = output[j]; } buffer[i] = 0; } } char DecimalToHexa(int rem) { char c = 0; if( rem >= 10) { c = (rem - 10) + 'A'; } else c = rem + '0'; return c; }
Last edited by Ancient Dragon; Apr 24th, 2007 at 1:20 pm.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
![]() |
Similar Threads
- Pascal and Hex etc (Pascal and Delphi)
- Armstrong numbers (C)
Other Threads in the C Forum
- Previous Thread: Subversion
- Next Thread: Urgent - Creating a Class named Half Adder
| Thread Tools | Search this Thread |
adobe api array arrays binarysearch calculate char cm convert copyanyfile copypdffile cprogramme createcopyoffile createprocess() csyntax directory dynamic feet fflush file floatingpointvalidation fork forloop frequency getlasterror givemetehcodez global graphics gtkgcurlcompiling hacking hardware highest homework i/o inches incrementoperators intmain() iso kernel kilometer km linked linkedlist linux linuxsegmentationfault list locate logical_drives loopinsideloop. match matrix microsoft motherboard mqqueue mysql oddnumber odf open opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc program programming pyramidusingturboccodes read recursion recv recvblocked repetition research scanf scheduling segmentationfault send shape socketprograming socketprogramming stack standard strchr string suggestions systemcall test unix urboc user variable voidmain() wab win32api windows.h






