码迷,mamicode.com
首页 > 其他好文 > 详细

中文字符

时间:2014-11-13 22:15:45      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:blog   io   ar   os   sp   for   div   log   bs   

#include<stdio.h>
#include <string>
#include <iostream>
using namespace std;


void char2Hex(char c) // 将字符以16进制表示
{
	char ch = ((c&0xF0)>>4)+‘0‘;
   // char ch = c/0x10 + ‘0‘; // 汉字占两位
	if( ch > ‘9‘ ) 
		ch += (‘A‘-‘9‘-1);
	char cl = (c&0x0f)+‘0‘;

	//char cl = c%0x10 + ‘0‘; 
	if( cl > ‘9‘ )
		cl += (‘A‘-‘9‘-1);
	cout << ch << cl << ‘ ‘;
}

int main(int,char**)
{
	char str[] = "中国";

	for( size_t i=0; i<strlen(str); ++i )
		char2Hex( str[i] );

	cout << endl;

	return 0;
}

 

中文字符

标签:blog   io   ar   os   sp   for   div   log   bs   

原文地址:http://www.cnblogs.com/kangbry/p/4095906.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!