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

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
MyScale Blog
MyScale Blog
博客园 - 叶小钗
U
Unit 42
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
有赞技术团队
有赞技术团队
F
Fortinet All Blogs
WordPress大学
WordPress大学
美团技术团队
GbyAI
GbyAI
L
LangChain Blog
T
The Blog of Author Tim Ferriss
P
Proofpoint News Feed
Y
Y Combinator Blog
V
Visual Studio Blog
小众软件
小众软件
D
Docker
量子位
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
人人都是产品经理
人人都是产品经理
C
CERT Recently Published Vulnerability Notes
AI
AI
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
C
Check Point Blog
I
InfoQ
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
S
Security Affairs
Stack Overflow Blog
Stack Overflow Blog
V
Vulnerabilities – Threatpost
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
TaoSecurity Blog
TaoSecurity Blog
L
Lohrmann on Cybersecurity
Hacker News: Ask HN
Hacker News: Ask HN
C
CXSECURITY Database RSS Feed - CXSecurity.com
N
News and Events Feed by Topic
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
W
WeLiveSecurity
V2EX - 技术
V2EX - 技术
SecWiki News
SecWiki News
PCI Perspectives
PCI Perspectives
S
Secure Thoughts
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 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