简体   繁体   English

C 中的小数八进制和十六进制转换说明符是什么?

[英]What are the fractional octal and hexadecimal conversion specifier in C?

I am aware that when using the printf function I can express the octal value of an integer with %o and its hexadecimal value with %x .我知道当使用printf function 时,我可以用%o表示 integer 的八进制值,用%x表示它的十六进制值。
How can I represent a floating-point value as octal or hexadecimal, though?但是,如何将浮点值表示为八进制或十六进制?
When trying to use the same specifiers, Xcode 13.x predictably throws a warning telling me I am trying to use an integer specifier with a floating-point value.当尝试使用相同的说明符时,Xcode 13.x 可以预见地抛出一个警告,告诉我我正在尝试使用带有浮点值的 integer 说明符。

How can I work around this?我该如何解决这个问题?
Thank you谢谢

You can format a float or double in hexadecimal using %a or %A (to use lowercase or uppercase letters, respectively).您可以使用%a%A (分别使用小写或大写字母)格式化十六进制的floatdouble精度数。 There is no conversion specifier for octal for floating-point.八进制浮点数没有转换说明符。

This formats the value.这会格式化值。 If you want to view the representation of the floating-point object, you should access its bytes using an unsigned char * , and then you can format those bytes using the o , x , or X conversion specifiers.如果要查看浮点 object 的表示形式,则应使用unsigned char *访问其字节,然后可以使用oxX转换说明符格式化这些字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM