FunctionRacerProblemsRace

Signed Byte String

EasyBitsPython, JavaScript, TypeScript, Java, C++

Return the 8 bit two's complement form of the integer n as a string of exactly 8 characters, each 0 or 1, highest bit first. For n >= 0 this is the binary form of n padded on the left with 0 characters to 8 places. For a negative n it is the 8 bit binary form of n + 256: for example -1 is 11111111 and -128 is 10000000.

Example 1

n 5
returns "00000101"

5 is 101 in binary, padded to eight characters.

Example 2

n -1
returns "11111111"

-1 + 256 = 255, which is 11111111 in binary.

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Bits problems