how to convert float to int preserving bit value

bit, c++, hlsl

Solution

In HLSL you should be able to do the following (assuming the value you are after is in f4.w)

uint ui = asuint( f4.w );
uint ui1 = ui & 0xffff;
uint ui2 = ui >> 16;

Basically it looks like the asuint intrinsic is your friend :)

Problem

I have a float4 coming into a compute shader, 3 of these floats are really floats but the fourth is 2 uints shifted together, how would i convert the float to uint by preserving the bit sequence instead of the numeric value? on the c++ side i solved it by creating a uint pointer, filling it with the desired number and passing on the pointer as a float pointer instead. However in hlsl as similar as it is to c/c++ there are no pointers so im stuck here :|

Original source