在VC中如何以十六进制的形式显示一个大小不定的字符串? 例如:字符串为:abcd 显示结果为:61 62 63 64 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 0a70: 98 9A 8E 7D 3F 23 43 5A 7B 9D;0a80: 34 2E 8E 7D 3F B4 43 C3 3C B1;0a90:.....0b00:.....做成这种效果,很常见的大家来帮帮忙分不够再加 不循环,岂有此理!顺序操作难道总耗时会少么?输出十六进制字符用%x/%X格式化操作符,sprint家族或CString::Format()等都可以用.格式化花不了多少时间的!想更高效直接查表输出,这是个小测试程序:#include <iostream>#include <assert.h>using namespace std ;#include <windows.h> void init_table() ;void format( char *pszOutput, const char *pszInput ) ;main() { char a[1024] ; const char * const b = "tes taidc" ; init_table() ; format( a, b ) ; cout<< a << endl ; return 1; }static char g_szTable[256][4] ;void init_table(){ for( int i = 0 ; i < 256 ; ++ i ) sprintf( g_szTable[i], "%02X ", i ) ;}void format( char *pszOutput, const char *pszInput ) { assert( pszOutput && pszInput ) ; while( *pszInput ) { memcpy( pszOutput, g_szTable[*pszInput++], 4 ) ;//32位机处理4字节是最快速的,故连最后的字串结束符一起复制 pszOutput += 3 ; }} MFC 与打印机 XListCtrl的header是flat,怎么让他正常显示,XListCtrl是1.5 Wininet实现FTP下载的问题 为什么VS2005中没有了DirectX功能? 视图分割后两个view的互动问题 求救!!!vc6中sdk编程,如何将位图的背景色透明???不能用MFC!!! 高分求解优化查找算法,请看帖子 小弟的考试题 2! 为何用CreateThread创建的线程无法运行呢? 警告: VC 6 编译器产生错误的优化代码 求msxml3资料 谁知道怎样检查出一个安装程序在电脑里装了哪些文件?
0a80: 34 2E 8E 7D 3F B4 43 C3 3C B1;
0a90:.....
0b00:.....
做成这种效果,很常见的
大家来帮帮忙
分不够再加
#include <iostream>
#include <assert.h>
using namespace std ;
#include <windows.h>
void init_table() ;
void format( char *pszOutput, const char *pszInput ) ;
main()
{
char a[1024] ;
const char * const b = "tes taidc" ;
init_table() ;
format( a, b ) ;
cout<< a << endl ;
return 1;
}
static char g_szTable[256][4] ;
void init_table()
{
for( int i = 0 ; i < 256 ; ++ i )
sprintf( g_szTable[i], "%02X ", i ) ;
}
void format( char *pszOutput, const char *pszInput )
{
assert( pszOutput && pszInput ) ;
while( *pszInput ) {
memcpy( pszOutput, g_szTable[*pszInput++], 4 ) ;//32位机处理4字节是最快速的,故连最后的字串结束符一起复制
pszOutput += 3 ;
}
}