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

推荐订阅源

T
Threat Research - Cisco Blogs
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
月光博客
月光博客
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
云风的 BLOG
云风的 BLOG
The Last Watchdog
The Last Watchdog
L
LINUX DO - 热门话题
酷 壳 – CoolShell
酷 壳 – CoolShell
WordPress大学
WordPress大学
AWS News Blog
AWS News Blog
美团技术团队
G
Google Developers Blog
宝玉的分享
宝玉的分享
www.infosecurity-magazine.com
www.infosecurity-magazine.com
C
CXSECURITY Database RSS Feed - CXSecurity.com
Recent Commits to openclaw:main
Recent Commits to openclaw:main
I
InfoQ
小众软件
小众软件
Google DeepMind News
Google DeepMind News
P
Privacy & Cybersecurity Law Blog
Stack Overflow Blog
Stack Overflow Blog
Webroot Blog
Webroot Blog
D
DataBreaches.Net
IT之家
IT之家
PCI Perspectives
PCI Perspectives
人人都是产品经理
人人都是产品经理
Hacker News: Ask HN
Hacker News: Ask HN
L
LangChain Blog
SecWiki News
SecWiki News
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cisco Blogs
T
Threatpost
P
Proofpoint News Feed
Y
Y Combinator Blog
Cloudbric
Cloudbric
T
Tor Project blog
量子位
博客园_首页
B
Blog
Hugging Face - Blog
Hugging Face - Blog
GbyAI
GbyAI
D
Darknet – Hacking Tools, Hacker News & Cyber 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