Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. ALGORITHM 1
  2.  
  3. Input: a positive integer n
  4. Output: a sequence of bits representing the number in binary.
  5. For an input of n = 11, the output should be (1, 0, 1, 1).
  6.  
  7. Step 0: start with an empty output sequence S = ()
  8. Step 1: if n is 0, return the sequence S.
  9. Step 2: divide n by 2 to get k with remainder r; r must be 0 or 1.
  10. Step 3: prepend r onto S. replace n with k.
  11. Step 4: go to step 1.
  12.  
  13. ALGORITHM 2
  14.  
  15. Input: a positive integer n
  16. Output: a sequence of bits representing the number in binary.
  17. For an input of n = 11, the output should be (1, 0, 1, 1).
  18.  
  19. Step 0: start with an empty output sequence S = ()
  20. Step 1: divide n by 2 to get k with remainder r; r must be 0 or 1.
  21. Step 2: prepend r onto S. replace n with k.
  22. Step 3: if n is 1, return the sequence S.
  23. Step 4: go to step 1.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement