CodePudding user response:
You have a problem the question itself (no matter what hexadecimal, memory is binary)Int a=0377;//octal, but it is still a int
Int b=0 x00ff;//hexadecimal, but it is still a int
Usigned int c=255;//decimal, unsigned int
Long long int d=255;//decimal, signed long integer
You want to convert a and b? Are int values, too, unless you are converted to strings, otherwise it's just a matter of memory hi-lo truncation,
CodePudding user response:
//octal, hexadecimal short unsigned integer and long integer transform
# include & lt; stdio.h>
Int main () {
Unsigned short int usi.
Unsigned long int uli.
Usi=0 xffffu;
Printf (" % % ho, % hx, hu \ n ", usi, usi, usi); 65535//177777 FFFF,
Uli=0 XFFFFFFFFL;
Printf (" % % % o, x, u \ n ", uli, uli, uli); 4294967295//37777777777, FFFFFFFF,
return 0;
}
CodePudding user response:
C Integer ConstantsAn "integer constant" is a decimal (base 10), octal (base 8), or hexadecimal (base 16) number that represents An integral value. Use the integer constants to represent An integer values that always be changed.
Syntax
The integer - constant:
A decimal - constant integer - suffix opt
Octal - constant integer - suffix opt
Hexadecimal - constant integer - suffix opt
A decimal - constant:
Nonzero - digit
A decimal - constant digit
Octal - constant:
0
Octal - constant octal digit -
Hexadecimal - constant:
0 x hexadecimal digit -
0 x hexadecimal digit -
Hexadecimal - constant hexadecimal digit -
Nonzero - digit: one of
1 2 3 4 5 6 7 8 9
Octal digit: - one of
0 1 2 3 4 5 6 7
Hexadecimal digit: - one of
0 1 2 3 4 5 6 7 8 9
A b c d e f
A B C D E F
The integer - suffix:
Unsigned - suffix long - suffix opt
Long - suffix unsigned - suffix opt
Unsigned - suffix: one of
U u
Long - suffix: one of
L l
64 - bit integer - suffix:
I64
Integer constants are positive unless they are preceded by a minus sign (-). The minus sign is interpreted as The unary arithmetic negation operator. (See unary arithmetic Operators in Chapter 4 for information about this operator.)
If an integer constant begins with the letters 0 x or 0 x, it is hexadecimal. If it begins with the digit 0, it is octal. Otherwise, it is assumed to be decimal.
The following lines are equivalent:
/*=0 x1c Hexadecimal representation for a decimal 28 */
034/*=Octal representation for a decimal 28 */
No white - space characters can separate the who of an integer constant. These examples show valid decimal, octal, and hexadecimal constants.
/* Decimal Constants */
10
132
32179
/* Octal Constants */
012
0204
076663
/* Hexadecimal Constants */
0 xa or 0 xa
0 x84
0 x7db3 or 0 x7db3