在C ++中将uint转换为float [英] Converting uint to float in C++
问题描述
我使用ReadProcessMemory为了获得4个字节。该函数允许我将它表示为unsigned int。我想代表这是一个浮动;或者换句话说使用此uint的字节表示形式用于我的浮动。
I'm using ReadProcessMemory in order to get 4 bytes. The function allows me to represent this as an unsigned int. I wish to represent this as a float; or in other words use the byte representation of this uint for my float. I've tried casting and it does not seem to work.
示例:
字节表示:
94 4E 2D 43
Example: byte representation: 94 4E 2D 43
uint:
1127042708
uint: 1127042708
float:
173.3069458 ...
float: 173.3069458..
任何帮助都会感激。
推荐答案
ReadProcessMemory $ c>指向void,所以你可以指向
float
。
float f;
ReadProcessMemory(hProcess, lpBaseAdress, &f, sizeof(f), NULL);
请注意,当 sizeof(unsigned int)!= sizeof float)
。
铸造将无法工作,因为它将取值,而不是整数的表示。
Casting won't work because it will take the value and not the representation of the integer.
这篇关于在C ++中将uint转换为float的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!