#include <stdio.h>#include<stdlib.h>#include<string.h>#include<locale.h>intMain () {inti,v; Charbs[ -]; Charb[ -]; CharGst9]; Charh[9]; Chars[4]; Char*e;//decimal integer to binary string;I=1024x768; Ltoa (I,b,2); sprintf (BS,"%032s", B); printf ("i=%d,bs=%s\n", i,bs);//decimal integer to hexadecimal string;I=1024x768; Ltoa (I,h, -); sprintf (HS,"%08s", h); printf ("i=%d,hs=%s\n", I,HS);//hexadecimal string converted to decimal numberstrcpy (HS,"00000400"); SSCANF (HS,"%x",&i); printf ("hs=%s,i=%d\n", hs,i);//the binary string is converted to a hexadecimal string;strcpy (BS,"00000000000000000000010000000000"); I=strtol (Bs,&e,2); Ltoa (I,h, -); sprintf (HS,"%08s", h); printf ("bs=%s,hs=%s\n", BS,HS);//Binary string converted to decimal number;strcpy (BS,"00000000000000000000010000000000"); I=strtol (Bs,&e,2); printf ("bs=%s,i=%d\n", bs,i);//hex string into binary stringstrcpy (HS,"00000400"); SSCANF (HS,"%x",&i); Ltoa (I,b,2); sprintf (BS,"%032s", B); printf ("hs=%s,bs=%s\n", hs,bs);//ASC\GBK strings to hex stringsstrcpy (s),"a Han"); I=0; while(1) { if(0==s[i]) Break; sprintf (HS+i*2,"%02x", (unsignedChar) s[i]); I++; } setlocale (Lc_all,"CHS"); printf ("s=%s,hs=%s\n", S,HS);//hexadecimal string converted to kanji (GBK) and character (ASC)strcpy (HS,"61BABA"); I=0; while(1) { if(1!=SSCANF (hs+i*2,"%2x", &v)) Break; S[i]=(Char) v; I++; } S[i]=0; printf ("hs=%s,s=%s\n", hs,s); return 0;}//i=1024,bs=00000000000000000000010000000000//i=1024,hs=00000400//hs=00000400,i=1024//bs=00000000000000000000010000000000,hs=00000400//bs=00000000000000000000010000000000,i=1024//hs=00000400,bs=00000000000000000000010000000000//S=a Han, Hs=61baba//Hs=61baba,s=a Han
Reprint: http://bbs.csdn.net/topics/390787012 idzhao4zhong1
Oh!
C + + encoding conversion