Skip to content

Instantly share code, notes, and snippets.

@pmj
Forked from jhorneman/rawBytesToFloat.cpp
Last active August 29, 2015 14:02
Show Gist options
  • Save pmj/b44d052bcbf5576977f1 to your computer and use it in GitHub Desktop.
Save pmj/b44d052bcbf5576977f1 to your computer and use it in GitHub Desktop.
float rawBytesToFloat(const char* _buffer)
{
static_assert(sizeof(u_long_type) == sizeof(float),"sizes must match!");
u_long_type net_int;
memcpy(&net_int, _buffer, sizeof(net_int));
u_long_type host_int = asio::detail::socket_ops::network_to_host_long(net_int);
float result;
memcpy(&result, &host_int, sizeof(result));
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment