Advertisement
milanmetal

[DTM] Shift bit-string to the right / v2

Oct 29th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.92 KB | None | 0 0
  1. // Input: a binary number n, for example 1101
  2. // Ouput: 01101
  3. //
  4. // Author: Milan Nedic
  5. //
  6.  
  7. name: Shift bit-string to the right v2
  8. init: to_the_right
  9. accept: qAccept
  10.  
  11. to_the_right,0
  12. to_the_right,0,>
  13.  
  14. to_the_right,1
  15. to_the_right,1,>
  16.  
  17. // to_the_right takes me to the first empty position on the right
  18.  
  19. // empty found? put the placeholder
  20. // and get back one place
  21. to_the_right, _                
  22. to_the_left, x, <  
  23.  
  24. // move back through all placeholders
  25. to_the_left, x
  26. to_the_left, x, <
  27.  
  28. // you saw 0 while moving back?
  29. // bring it forward one place
  30. to_the_left, 0
  31. bring_0, x, >
  32.  
  33. bring_0, 0
  34. bring_0, x, >
  35.  
  36. bring_0, x
  37. to_the_left, 0, <
  38.  
  39. // ---------------------
  40. // you saw 1 while moving back?
  41. // bring it forward one place
  42. to_the_left, 1                 
  43. bring_1, x, >  
  44.  
  45. bring_1, 1
  46. bring_1, x, >
  47.  
  48. bring_1, x
  49. to_the_left, 1, <
  50.  
  51. to_the_left,_              
  52. clear_placeholder,_, >             
  53.    
  54. clear_placeholder, x         
  55. qAccept, 0, -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement