数值包括整数、浮点数。整数分有符号、无浮号,浮点数分单精度、双精度。
1 2 3 4 |
int a =100;//数值:有符号 unsingle int b = 100;//数值:无符号 float c = 100.09; //数值:单精度 double d = 100.09; //数值:双精度 |
具体类型占多少位,可以用sizeof获取。可以看:基本类型的字节长度
如果数值是100、-1、12.333想知道这些数值在内存中二进制是怎样的,有什么办法没有?
当然是有办法的,C++中有一个bitset类,就是用来处理bit位的一个封装。
数值在内存中二进制表示代码如下:
输出结果二进制:
00000000 00000000 00000000 01100100
11111111 11111111 11111111 11111111
01000000 00101000 10101010 01111110 11111001 11011011 00100010 11010001
讲下这段函数部份:
1 2 |
char* low = (char*)&t; char* high = (char*)(&t+1)-1; |
这两句作用会比较不好理解,特别是第二句。
(char*)&t;? ?取T类型地址,转成char*指针。
(char*)(&t+1)-1;? 取T类型地址,T*指针加1,转成char*指针,char*指针减1。
画个图表示,当T是int类型进行说明,其它数值类型原理一样。
wihle循环就是从高位到低位输出二进制。
With thanks, A good amount of knowledge!
diflucan
Helpful postings. Thank you. diflucan for yeast infection
You suggested that well! global pharmacy canada
Cheers. Useful stuff! hemp oil cbd
Good forum posts. With thanks! canada pharmaceutical online ordering
You’ve made your point extremely well!! aarp approved canadian online pharmacies
Thanks a lot! Lots of data!
fda kratom
Cheers, I like it! provigil lawsuit
Excellent advice. Regards. ed meds online without doctor prescription
Nicely put. Thanks a lot! canada pharmacies online prescriptions
Wonderful posts. Thank you! Zovirax Cream Cost Without Insurance
Thanks a lot, I value this. bactrim ds
With thanks. Lots of facts.
online canadian pharmacy
This is nicely put. ! canadian pharmacies online
Many thanks. Numerous advice.
hemp oil for sale walmart
Lovely postings, With thanks! canadian cialis
Nicely put, With thanks. Take Together Lisinopril And Metoprolol
You explained this superbly! Cipro Dose For Cats
Truly tons of great info! canadian pharmacies that ship to us
Wow all kinds of great info. what is cbd