Simple Sand Samples |
C言語 > 文字列を数値に変換する(文字コードを得る)
str2hex.c
#include <stdio.h> int main() { char str[] = "HELLO"; char *p=str; while(1){ if(*p == '\x0')break; printf("%02x\n",*p++); } return 0; }
$ gcc str2hex.c
$ ./a.out
48
45
4c
4c
4f
$
$ ./a.out
48
45
4c
4c
4f
$
* 確認環境 Debian Linux(Wheezy)