log2 (x) is tough
Computing K is easy, just find the order of the leftmost ‘1’ bit:
log2(32) => 100000 => K = 5
log2(51) => 110011 => K= 5, XXXX = ??? (.6724)
To compute XXXX accurately, must use power series or lookup table. An approximation would be to simply treat the remaining bits as a fixed point fraction and use linear interpolation:
51 => 110011 => K=5, 0.XXXX = 0.10011
? = 5, frac (?) = 0.10011 => (.59375)
Lookup table is probably preferred solution.