Binary

View as PDF

Submit solution


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 N (1 \le N \le 20), the number of numbers to convert to binary. The next N lines will be i such that (i \in \mathbb{Z}, 0 \le i \le 10^9).

Output Specification

For every integer i, 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

Comments


  • 0
    VervetMonkey
     commented on July 15, 2017

    im new too python may anyone please tell me how to figure out these problems i am confused on what he is sasking me to do. What does this mean? > N N ( 1 ≤ N ≤ 20 1 \le N \le 20 ). and this? > The next N N lines will be i i such that ( i ∈ Z , 0 ≤ i ≤ 10 9 i \in \mathbb{Z}, 0 \le i \le 10^9 ).I would be very grateful if you could help me.


  • -2
    Pleedoh
     commented on May 28, 2017 edited

    .


  • 2
    Shehryar
     commented on Jan. 2, 2017
    Hint

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


    • 0
      max
       commented on Aug. 9, 2017

      Other Hint: Python3 has a function called 'bin'


  • 1
    acetao
     commented on Jan. 27, 2016 edit 3
    output must be a group with four digits

    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


  • 0
    Ish_God
     commented on Nov. 15, 2015
    OLE

    what is the output if the input is 0


    • -1
      Xyene
       commented on Nov. 15, 2015
      0000

  • 0
    niamp
     commented on Nov. 10, 2015 edited
    Right answers but no points

    I tested my solution using eclipse and all the test cases are correct, why am I getting WA in my submissions?

    UPDATE: Nvm, I was making a stupid mistake


  • 0
    Anix55
     commented on Oct. 24, 2015
    help pls

    I can't get the first text case to work...is anyone having a similar problem?


  • 0
    moladan123
     commented on Jan. 24, 2015
    What?

    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?


    • 2
      FatalEagle
       commented on Jan. 24, 2015

      There is more than one input.