## Binary

View as PDF

Points: 5
Time limit: 2.0s
Memory limit: 64M

Author:
Problem types

Your computer science teacher has kindly requested that you write a program to convert a number, inputted in decimal, to binary to help in teaching students about binary. Also to aid in human processing of numbers, you should group every four bits and separate the groups by space.

#### Input Specification

The first line will be integer (), the number of numbers to convert to binary. The next lines will be such that ().

#### Output Specification

For every integer , output the binary representation, grouped into four bit groups, separated by spaces. If necessary, you must pad the first group to have exactly four bits.

#### Sample Input

3
1
10
255

#### Sample Output

0001
1010
1111 1111

• commented on June 2, 2019, 10:13 a.m.

I think the Haskell compiler is a bit outdated, I can't use Data.List.Split libraries :( .

• commented on Oct. 31, 2017, 3:01 p.m.

Is it possible to see the input for test case 1, 7th conversion (8th line of input)? My students and I are getting WA for this case, but are ACing all the other test cases. I'm sure it's something minor, but we're a bit stumped right now.

• commented on Oct. 31, 2017, 3:29 p.m.

You aren't handling the case where .

• commented on Oct. 31, 2017, 5:01 p.m. edited

Thanks!

• commented on Jan. 2, 2017, 6:03 a.m.

Java has a method you can call against the Integer class: Integer.toBinaryString(number);

• commented on Aug. 9, 2017, 10:32 a.m.

Other Hint: Python3 has a function called 'bin'

• commented on Jan. 27, 2019, 2:01 p.m.

I had been making a "gen_binary" function and all this time there was one built-in! I still need to refine the "bin"'s output though, so the "gen_binary" function won't be useless.

• commented on Jan. 27, 2016, 6:04 a.m. edit 3

Note the output specification: (1) 16 --> 10000,output should be:
0001 0000,output should not be:1000 0 (2) 0 --> 0000,1 --> 0001, 7 --> 0111

• commented on Nov. 15, 2015, 11:28 p.m.

what is the output if the input is 0

• commented on Nov. 16, 2015, 12:04 a.m.
0000
• commented on Jan. 25, 2015, 2:12 a.m.

It seems that im getting the right answers, but im still getting wa. Is there anything wrong with how i'm using sys.stdout.write?

• commented on Jan. 25, 2015, 2:15 a.m.

There is more than one input.