进制转换
字节= byte;
1byte = 8 bit
字节通常简写为“B”,而位通常简写为小写“b”;
1KB(Kilobyte,千字节)=1024B= 2^10 B;
1MB(Megabyte,兆字节,百万字节,简称“兆”)=1024KB= 2^20 B;
1GB(Gigabyte,吉字节,十亿字节,又称“千兆”)=1024MB= 2^30 B;
1TB(Terabyte,万亿字节,太字节)=1024GB= 2^40 B;
1PB(Petabyte,千万亿字节,拍字节)=1024TB= 2^50 B;
1EB(Exabyte,百亿亿字节,艾字节)=1024PB= 2^60 B;
1ZB(Zettabyte,十万亿亿字节,泽字节)= 1024EB= 2^70 B;
1YB(Yottabyte,一亿亿亿字节,尧字节)= 1024ZB= 2^80 B;
1BB(Brontobyte,一千亿亿亿字节)= 1024YB= 2^90 B;
1NB(NonaByte,一百万亿亿亿字节) = 1024BB = 2^100 B;
1DB(DoggaByte,十亿亿亿亿字节) = 1024 NB = 2^110 B;
数据存储是以10进制表示,数据传输是以2进制表示的,所以1KB不等于1000B。
每8个位(bit,简写为b)组成一个字节(Byte,简写为B),1B(byte,字节)= 8 bit;
常用基本数据类型占用空间(64位机器为例)
char : 1个字节
int :4个字节
float:4个字节
double:8个字节
对于下列代码:
cout << sizeof(int) << endl;
cout << sizeof(char) << endl;
cout << sizeof(float) << endl;
cout << sizeof(double) << endl;
cout << sizeof(100) << endl;
cout << sizeof(1.0) << endl;
cout << sizeof('a') << endl;
cout << sizeof("a") << endl;
cout << sizeof("abc!") << endl;
有:
命令 | 结果 |
---|---|
sizeof(int) | 4 |
sizeof(char) | 1 |
sizeof(float) | 4 |
sizeof(double) | 8 |
sizeof(100) | 4 |
sizeof(1.0) | 8 |
sizeof(‘a’) | 1 |
sizeof(‘abc’) | 4 |
sizeof(“a”) | 2 |
sizeof(“abc!”) | 5 |
基本类型:
整数
进制 | 例子 |
---|---|
10进制 | 100 |
以0b开头为2进制 | 10110011 |
以0开头为8进制 | 01234567 |
以0x开头为16进制 | 0xABCDEF |
小数
单精度常量:2.3f 。
双精度常量:2.3,默认为双精度。
字符型常量
用英文单引号括起来,只保存一个字符’a’、‘b’ 、’*’ ,还有转义字符 ‘\n’ 、’\t’。
字符串常量
用英文的双引号引起来 可以保存多个字符:“abc”。
厂家磁盘容量标称值 X,实际磁盘容量 Y,有Y=0.931*X,是因为(1000 / 1024)^3约为0.931。
以下转自菜鸟教程:[原文链接]
#include<iostream>
#include <limits>
using namespace std;
int main()
{
cout << "type: \t\t" << "************size**************"<< endl;
cout << "bool: \t\t" << "所占字节数:" << sizeof(bool);
cout << "\t最大值:" << (numeric_limits<bool>::max)();
cout << "\t\t最小值:" << (numeric_limits<bool>::min)() << endl;
cout << "char: \t\t" << "所占字节数:" << sizeof(char);
cout << "\t最大值:" << (numeric_limits<char>::max)();
cout << "\t\t最小值:" << (numeric_limits<char>::min)() << endl;
cout << "signed char: \t" << "所占字节数:" << sizeof(signed char);
cout << "\t最大值:" << (numeric_limits<signed char>::max)();
cout << "\t\t最小值:" << (numeric_limits<signed char>::min)() << endl;
cout << "unsigned char: \t" << "所占字节数:" << sizeof(unsigned char);
cout << "\t最大值:" << (numeric_limits<unsigned char>::max)();
cout << "\t\t最小值:" << (numeric_limits<unsigned char>::min)() << endl;
cout << "wchar_t: \t" << "所占字节数:" << sizeof(wchar_t);
cout << "\t最大值:" << (numeric_limits<wchar_t>::max)();
cout << "\t\t最小值:" << (numeric_limits<wchar_t>::min)() << endl;
cout << "short: \t\t" << "所占字节数:" << sizeof(short);
cout << "\t最大值:" << (numeric_limits<short>::max)();
cout << "\t\t最小值:" << (numeric_limits<short>::min)() << endl;
cout << "int: \t\t" << "所占字节数:" << sizeof(int);
cout << "\t最大值:" << (numeric_limits<int>::max)();
cout << "\t最小值:" << (numeric_limits<int>::min)() << endl;
cout << "unsigned: \t" << "所占字节数:" << sizeof(unsigned);
cout << "\t最大值:" << (numeric_limits<unsigned>::max)();
cout << "\t最小值:" << (numeric_limits<unsigned>::min)() << endl;
cout << "long: \t\t" << "所占字节数:" << sizeof(long);
cout << "\t最大值:" << (numeric_limits<long>::max)();
cout << "\t最小值:" << (numeric_limits<long>::min)() << endl;
cout << "unsigned long: \t" << "所占字节数:" << sizeof(unsigned long);
cout << "\t最大值:" << (numeric_limits<unsigned long>::max)();
cout << "\t最小值:" << (numeric_limits<unsigned long>::min)() << endl;
cout << "double: \t" << "所占字节数:" << sizeof(double);
cout << "\t最大值:" << (numeric_limits<double>::max)();
cout << "\t最小值:" << (numeric_limits<double>::min)() << endl;
cout << "long double: \t" << "所占字节数:" << sizeof(long double);
cout << "\t最大值:" << (numeric_limits<long double>::max)();
cout << "\t最小值:" << (numeric_limits<long double>::min)() << endl;
cout << "float: \t\t" << "所占字节数:" << sizeof(float);
cout << "\t最大值:" << (numeric_limits<float>::max)();
cout << "\t最小值:" << (numeric_limits<float>::min)() << endl;
cout << "size_t: \t" << "所占字节数:" << sizeof(size_t);
cout << "\t最大值:" << (numeric_limits<size_t>::max)();
cout << "\t最小值:" << (numeric_limits<size_t>::min)() << endl;
cout << "string: \t" << "所占字节数:" << sizeof(string) << endl;
// << "\t最大值:" << (numeric_limits<string>::max)() << "\t最小值:" << (numeric_limits<string>::min)() << endl;
cout << "type: \t\t" << "************size**************"<< endl;
return 0;
}
运行结果: