Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - How to define binary numbers in C language
How to define binary numbers in C language
There is no such type as binary number in C language, so there is no way to define it directly. But you can directly define the hexadecimal number of 16.

Example:

int main(){

int a;

scanf("%p ",& ampa); // 16 hexadecimal number input %p is to input a hexadecimal number scanf ("%llx ",&; a); You can also enter hexadecimal, which is more formal.

printf("%d ",a); //Decimal output %d is a decimal number.

printf("0x%x ",a); // 16 binary output printf("%llX\n ",a); You can also output a hexadecimal number. If the red part is uppercase X, hexadecimal output is uppercase letters, otherwise lowercase X is lowercase letters.

}

Extended data

C language defines the hexadecimal number of integer data;

Unsigned inthex _ val = 0x123;

//Define an integer variable and assign the initial value to a hexadecimal constant.

if (scanf("%x ",& amphex_val)! = EOF)

{

Printf ("its octal and decimal values are =%o, %d\n", hex_val, hex _ val, respectively);

}