从C中的32位浮点数中提取位 [英] extract bits from 32 bit float numbers in C
本文介绍了从C中的32位浮点数中提取位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
32位使用IEEE格式以二进制表示.那么如何提取这些位呢?像&这样的按位运算和|不要对他们工作!我基本上想做的是从opencv中的32位浮点图像中提取LSB提前谢谢!
32 bits are represented in binary using the IEEE format. So how can I extract those bits? Bitwise operations like & and | do not work on them! what i basically want to do is extract the LSB from 32 bit float images in opencv thanx in advance!
推荐答案
#include<stdio.h>
union abc
{
float fo;
unsigned int no;
};
int main()
{
union abc test;
test.fo=36.5;
unsigned int x=test.no;
for( int i = 0; i < sizeof(float)*8; i++ )
{
printf("%d", x & 0x1);
x = x >> 1;
}
return 0;
}
这是一种提取浮点数的方法!
this was a way to extract the bits of the float!
这篇关于从C中的32位浮点数中提取位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文