Advertisement
Guest User

Untitled

a guest
Apr 16th, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. -- Returns number of bits required to represent val in binary vector
  2. function bits_req(val : natural) return natural is
  3. variable res_v : natural; -- Result
  4. variable remain_v : natural; -- Remainder used in iteration
  5. begin
  6. res_v := 0;
  7. remain_v := val;
  8. while remain_v > 0 loop -- Iteration for each bit required
  9. res_v := res_v + 1;
  10. remain_v := remain_v / 2;
  11. end loop;
  12. return res_v;
  13. end function;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement