user-0 提问: C语言中关于转换说明的疑惑

回复:
user: user-0
content: 引用 5 楼 forever74的回复:[quote=引用 4 楼 西厢赏月 的回复:] 有没有%luo、%lux，%huo、%hux这几种形式？  Try it first, and throw your conclusion.[/quote] Thank you.

user: user-1
content: 引用 4 楼 西厢赏月 的回复:[quote=引用 2 楼 赵4老师的回复:]//八进制、十六进制无符号短整型和长整型转换 #include <stdio.h> int main() {     unsigned short int usi;     unsigned long  int uli;      usi=0xFFFFu;     printf("%ho,%hx,%hu\n",usi,usi,usi);//177777,ffff,65535     uli=0xFFFFFFFFl;     printf("%o,%x,%u\n",uli,uli,uli);//37777777777,ffffffff,4294967295     return 0; }  有没有%luo、%lux，%huo、%hux这几种形式？[/quote] https://docs.microsoft.com/en-us/cpp/c-runtime-library/format-specification-syntax-printf-and-wprintf-functions?redirectedfrom=MSDN&view=msvc-160

user: user-2
content: 引用 4 楼 西厢赏月 的回复:有没有%luo、%lux，%huo、%hux这几种形式？  Try it first, and throw your conclusion.

user: user-0
content: 引用 2 楼 赵4老师的回复://八进制、十六进制无符号短整型和长整型转换 #include <stdio.h> int main() {     unsigned short int usi;     unsigned long  int uli;      usi=0xFFFFu;     printf("%ho,%hx,%hu\n",usi,usi,usi);//177777,ffff,65535     uli=0xFFFFFFFFl;     printf("%o,%x,%u\n",uli,uli,uli);//37777777777,ffffffff,4294967295     return 0; }  有没有%luo、%lux，%huo、%hux这几种形式？

user: user-1
content: C Integer Constants An “integer constant” is a decimal (base 10), octal (base 8), or hexadecimal (base 16) number that represents an integral value. Use integer constants to represent integer values that cannot be changed.  Syntax  integer-constant :  decimal-constant integer-suffix opt octal-constant integer-suffix opt hexadecimal-constant integer-suffix opt  decimal-constant :  nonzero-digit decimal-constant digit  octal-constant :  0 octal-constant octal-digit  hexadecimal-constant :  0x hexadecimal-digit 0X 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  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 0x or 0X, 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:  0x1C   /* = Hexadecimal representation for decimal 28 */ 034    /* = Octal representation for decimal 28 */  No white-space characters can separate the digits 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 */ 0xa or 0xA 0x84 0x7dB3 or 0X7DB3

user: user-1
content: //八进制、十六进制无符号短整型和长整型转换 #include <stdio.h> int main() {     unsigned short int usi;     unsigned long  int uli;      usi=0xFFFFu;     printf("%ho,%hx,%hu\n",usi,usi,usi);//177777,ffff,65535     uli=0xFFFFFFFFl;     printf("%o,%x,%u\n",uli,uli,uli);//37777777777,ffffffff,4294967295     return 0; }

user: user-3
content: 你这个问题问的本身就有问题（不管什么进制，内存都是二进制） int a=0377; //八进制，但是它到底还是个int int b=0x00ff; //16进制，但是它到底还是个int usigned int c = 255; //10进制，无符号int long long int d = 255; //10进制，有符号长整型 a和b你想怎么转换？都是int，值也一样。除非你转成字符串来表示，否则只是内存高低位截断的问题。