:c語言漢字轉化成二進位制程式碼
**********************************************************
***********************************************************
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
/*
漢字轉化成二進位制碼
*/
void conv(char *c)
{
char ch[9] = {'\0'};
int i;
int j = 0;
int count = 0;
char t[3] = {'\0'};
while('\0' != c[j])
{
for(i = 7;i >= 0;i--)
{
ch[i] = (c[j]&1)+'0';
//右移
c[j]>>=1;
}
printf("%s\t",ch);
j++;
}
}
int main()
{
char use;
char c[100];
printf("本程式實現漢字的二進位制編碼翻譯功能\n確認開始程式?(y/n)");
use = getch();
while(use =='y' || use =='Y')
{
printf("\n請輸入要轉化的字 :");
scanf("%s",c);
conv(c);
printf("是否繼續轉換(y/n)");
use = getch();
}
system(" PAUSE");
return 0;
}
********************************************************
***********************************************************
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
//漢字轉化成16進位制
int main()
{
char c[10] = "哈爾濱";
for(int i=0;i<6;i++)
{
printf("%x\n",c[i]&0xff);
}
system("pause");
return 0;
}