C ++: dec, hex y OCT (decimal, hexadecimal, octal)

se detalla:

diciembre decimal como cout<<dec<<bserá convertido a decimal y luego b de salida

El hexadecimal hexagonal cout<<hex<<bse convertirá en la re-salida hexadecimal b

Como es octal octubre cout<<oct<<bse convertirá en un re-salida octal b

Ejemplo 1:

#include<iostream>
using namespace std;
int main() {
  int n = 16;
  cout << dec << n << endl;
  cout << oct << n << endl;
  cout << hex << n << endl;
 
  return 0;
}
//输出:16 20 10

Ejemplo 2:

El formato predeterminado es decimal dec, antes de modificar el formato del formato original permanecerá en vigor. Uso hexagonal y valor decimal formato hexadecimal octal octubre 42

void hexoct2(void)
{
	int chest=42;
	int waist=42;
	int inseam=42;
 
	cout<<"monsieur cuts a striking figure!"<<endl;
	cout<<"chest="<<chest<<" (decimal for 42)"<<endl;
	cout<<hex;//manipulator for changing number base
	cout<<"waist="<<waist<<" (hexadecimal for 42)"<<endl;
	cout<<oct;//manipulator for changing number base
	cout<<"inseam="<<inseam<<" (octal for 42)"<<endl;
 
	cin.get();
}

Aquí Insertar imagen Descripción
Tomado de:
Referencia 1
Referencia 2
Referencia 3
si equivocadas, cartas privadas I, a retirar inmediatamente

Publicado tres artículos originales · ganado elogios 0 · Vistas 249

Supongo que te gusta

Origin blog.csdn.net/weixin_43991826/article/details/105187858
Recomendado
Clasificación