Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Input: a binary number n, for example 1101
- // Ouput: 01101
- //
- // Author: Milan Nedic
- //
- name: Shift bit-string to the right v2
- init: to_the_right
- accept: qAccept
- to_the_right,0
- to_the_right,0,>
- to_the_right,1
- to_the_right,1,>
- // to_the_right takes me to the first empty position on the right
- // empty found? put the placeholder
- // and get back one place
- to_the_right, _
- to_the_left, x, <
- // move back through all placeholders
- to_the_left, x
- to_the_left, x, <
- // you saw 0 while moving back?
- // bring it forward one place
- to_the_left, 0
- bring_0, x, >
- bring_0, 0
- bring_0, x, >
- bring_0, x
- to_the_left, 0, <
- // ---------------------
- // you saw 1 while moving back?
- // bring it forward one place
- to_the_left, 1
- bring_1, x, >
- bring_1, 1
- bring_1, x, >
- bring_1, x
- to_the_left, 1, <
- to_the_left,_
- clear_placeholder,_, >
- clear_placeholder, x
- qAccept, 0, -
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement