| | |
Convert string to to HEX
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
You can pass character by character to itoa with radix 16.
If you only want to display the hex values, you can use printf with format specifiers %x or %X.
If you only want to display the hex values, you can use printf with format specifiers %x or %X.
バルサミコ酢やっぱいらへんで
•
•
Join Date: Jun 2006
Posts: 61
Reputation:
Solved Threads: 0
•
•
•
•
Originally Posted by WolfPack
You can pass character by character to itoa with radix 16.
If you only want to display the hex values, you can use printf with format specifiers %x or %X.
Regards
If you use the radix 10, you will get a string of the an integer in base 10.
For radix 16, you will get a hexadecimal string.
You can try the example in the given web page or the one below.
e.g
For radix 16, you will get a hexadecimal string.
You can try the example in the given web page or the one below.
e.g
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> #include <stdlib.h> int main() { char name[10]="stephen"; char buffer[21]=""; char *pbuffer = buffer; int len = strlen( name ); for( int i = 0; i < len ;i++ ) { itoa (name[i],pbuffer,16); pbuffer +=2; }; printf( "%s\n", buffer ); return 0; }
バルサミコ酢やっぱいらへんで
•
•
•
•
Originally Posted by sgriffiths
I cant see no given web page,
バルサミコ酢やっぱいらへんで
•
•
•
•
Originally Posted by sgriffiths
When i try to compile, i get this
> gcc string_to_hex.c
Undefined first referenced
symbol in file
itoa /tmp/cc21JKaJ.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status
http://www.daniweb.com/techtalkforum...highlight=itoa
or use this code
C Syntax (Toggle Plain Text)
#include <stdio.h> #include <string.h> int main() { char name[10]="STEPHEN"; char buffer[21]=""; char *pbuffer = buffer; int len = strlen( name ); int i; for(i = 0; i < len ;i++ ) { sprintf(pbuffer, "%x", name[i]); pbuffer +=2; } printf( "%s\n", buffer ); return 0; }
Compiled with gcc
Last edited by andor; Jul 6th, 2006 at 6:07 am.
If you want to win, you must not loose (Alan Ford)
What are you guys taking about? The original request is:
What does this mean?
1) "STEPHEN" is not a number so it can't be converted to Hex
or
2) "STEPHEN" is a string of characters that each have a Hex value. Do you mean add these characters to get a value?
Maybe an actual example would be in order. After the conversion, what should the Hex value of "STEPHEN" be?
•
•
•
•
Originally Posted by sgriffiths
how would i go about converting a string value to HEX
ie
char name[10]="STEPHEN";
Convert name to HEX
1) "STEPHEN" is not a number so it can't be converted to Hex
or
2) "STEPHEN" is a string of characters that each have a Hex value. Do you mean add these characters to get a value?
Maybe an actual example would be in order. After the conversion, what should the Hex value of "STEPHEN" be?
![]() |
Views: 36612 | Replies: 22
| Thread Tools | Search this Thread |
Tag cloud for C
#include * append array arrays bash binarysearch changingto char character cm copyanyfile copypdffile createprocess() database directory drawing dynamic execv feet fgets file floatingpointvalidation fork framework function functions getlogicaldrivestrin givemetehcodez global grade graphics gtkwinlinux histogram homework i/o ide include infiniteloop initialization input interest intmain() iso keyboard kilometer lazy license linked linkedlist linux list looping loopinsideloop. lowest matrix meter microsoft mqqueue mysql oddnumber odf open openwebfoundation overwrite pause pdf pointer pointers posix power process program programming pyramidusingturboccodes read recursion recv recvblocked reversing segmentationfault single socket socketprogramming spoonfeeding standard strchr string student suggestions system test testing threads unix urboc user whythiscodecausesegmentationfault win32api windowsapi






