The TransCompilator

Solved LeetCode program · 781 of 1,000

#1017 · Convert to Base -2

Medium Math chunk-16.md

Original English source

The number is 2. The rest is number. The reversed is an empty list of text.
Repeat while rest is not 0.
The bit is rest modulo 2. If bit is less than 0, set bit to 0 minus bit. The piece is format whole number bit as text. Place piece into reversed. The adjusted is rest minus bit. Set rest to adjusted divided by -2.

The result is empty text. The last is the last position of reversed.
For every step from 0 to last.
The place is last minus step. Place item place of reversed into result.

Show result.

Open in Playground Browse all 1,000 problems

Expected stdout

110