@turing-machine-js/library-binary-numbers
A library for the turing-machine-js.
Install
Using npm:
npm install @turing-machine-js/library-binary-numbers
or using yarn:
yarn add @turing-machine-js/library-binary-numbers
A concept
Binary numbers are represented as a sequence of symbols 0
and 1
.
A representation of a number starts with symbol ^
and ends with symbol $
.
For example:
-
^$
stands for 0 -
^1$
stands for 1 -
^10$
stands for 2 -
^11$
stands for 3 - etc.
There is no ability to work with negative numbers at this time.
This library provides following objects to work with binary numbers:
-
getTapeBlock
- this function returns aTapeBlock
class instance. It has only one tape. An alphabet of the tape contains the following symbols:space
as a blank symbol,^
,$
,0
and1
. -
states
- followingStates
class instances which represent some algorithms:-
goToNumber
- move the head to the number's end -
goToNextNumber
- move the head to the next number (to the right) -
goToPreviousNumber
- move the head to the previous number (to the left) -
deleteNumber
- delete the current number -
goToNumbersStart
- move the head to the number's start -
invertNumber
- change every symbol in the number to it's opposite one (0
to1
and1
to0
) -
normalizeNumber
- delete leading zeros -
plusOne
- add 1 to the number -
minusOne
- subtract 1 from the number
-
If you want to use states which were described earlier, you must use a tape block received from the getTapeBlock
function.
Links
- The information about
TapeBlock
andState
classes is here - Turing Machine on the Wikipedia