惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
博客园 - 叶小钗
Blog — PlanetScale
Blog — PlanetScale
Microsoft Azure Blog
Microsoft Azure Blog
Vercel News
Vercel News
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
MyScale Blog
MyScale Blog
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
量子位
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
Martin Fowler
Martin Fowler
阮一峰的网络日志
阮一峰的网络日志
D
Docker
Jina AI
Jina AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The Register - Security
The Register - Security
J
Java Code Geeks
S
SegmentFault 最新的问题
月光博客
月光博客
G
Google Developers Blog
美团技术团队
Last Week in AI
Last Week in AI
L
LangChain Blog
Apple Machine Learning Research
Apple Machine Learning Research
T
The Blog of Author Tim Ferriss
腾讯CDC
Recent Announcements
Recent Announcements
Recorded Future
Recorded Future
The Cloudflare Blog
有赞技术团队
有赞技术团队
博客园_首页
博客园 - 聂微东
人人都是产品经理
人人都是产品经理
B
Blog
I
InfoQ
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
F
Fortinet All Blogs
B
Blog RSS Feed
Engineering at Meta
Engineering at Meta
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Microsoft Security Blog
Microsoft Security Blog
MongoDB | Blog
MongoDB | Blog
爱范儿
爱范儿
D
DataBreaches.Net
F
Full Disclosure
M
MIT News - Artificial intelligence
博客园 - 司徒正美
H
Help Net Security

博客园 - Zero Lee

调用栈(call stack) 关于STL allocator Calculate maximum sum of any subarray set Calcuate power n of x recursively Convert one binary search tree to double-linked list 设计包含min函数的栈 类模板的模板友元函数定义 一道百度的面试题解答 一道腾讯面试题 (转)C++中extern “C”含义深层探索 selection algorithm to select nth small elements based on partition 删除与某个字符相邻且相同的字符 产生全排列的方法解析 一组数的全排列和组合程序实现 求一个正整数的平方根程序实现 [转]多线程队列的算法优化 [转载] STL allocator的介绍和一个基于malloc/free的allocator的简单实现 如何将一片内存链接成链表 One simple counted object pointer
非printf形式的十六进制和二进制打印(雅虎面试题)
Zero Lee · 2012-06-17 · via 博客园 - Zero Lee

编程实现:把十进制数(long型)分别以二进制和十六进制形式输出,不能使用printf系列

 1 template <typename T>
 2 void displayHexBin(const T& v)
 3 {
 4     const unsigned char c2h[] = "0123456789ABCDEF";
 5     const unsigned char c2b[] = "01";
 6 
 7     unsigned char* p = (unsigned char*)&v;
 8     char* buf = new char [sizeof(T)*2+1];
 9     char* ptmp = buf;
10     p = p + sizeof(T)-1;
11     for (int i = 0; i < sizeof(T); i++, --p) {
12         *buf++ = c2h[*p >> 4];
13         *buf++ = c2h[*p & 0x0F];
14     }
15     *buf = '\0';
16     printf("hex format displayed as %s\n", ptmp);
17 
18     delete [] ptmp;
19     p = (unsigned char*)&v; p = p + sizeof(T)-1;
20     ptmp = buf = new char [sizeof(T)*8+1];
21     for (int i = 0; i < sizeof(T); i++, --p) {
22         for (int j = 0; j < 8; j++)
23             *buf++ = c2b[(*p >> (7-j)) & 0x1];
24     }
25     *buf = '\0';
26     printf("bin format displayed as %s\n", ptmp);
27     delete [] ptmp;
28 }
29