15
1
Given a binary integer inclusively between 0
and 1111111111111111
(i.e. a 16-bit unsigned integer) as input, output the same integer in negabinary.
The input can be in whatever format is most convenient for your language; for example, if it is easier for the program to handle input with 16 digits, like 0000000000000101
, rather than simply 101
, you can write the program to only accept input that way.
Sample I/O
> 1
1
> 10
110
> 1010
11110
> 110111001111000
11011001110001000
> 1001001
1011001
Here is a sample program I wrote that does base conversions, including negative and non-integer bases. You can use it to check your work.
2The link appears to be down, which is a prime reason for why we require questions to be self-contained these days – Jo King – 2019-11-28T23:00:05.023
Just to clarify a bit further, the input and output would have to be binary, right? I mean: character strings of
0
s and1
s. Looks clear to me, but an answer makes me doubt lightly... – Joanis – 2012-01-07T05:21:46.583@M.Joanis The input is binary, the output is negabinary (which looks exactly the same as binary--a string of zeroes and ones--but the way the number is interpreted is different.) – Peter Olson – 2012-01-07T14:58:37.523