6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

浮動小数点型を16進数表示

Posted at

あまり使う機会はないが覚えておくと役に立つかも。
float型などのbit表現をprintfで確認したい時は、一度unionでキャストしてから表示する。

#include <stdio.h>
#include <stdint.h>

int
main()
{
	printf("%08x\n", ((union {float f; uint32_t ui;})((float)1.00)).ui);
}

出力は「3f800000」となり、IEEE754に従っていることが確認できる。

6
6
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?