Topic 1473: Binary number

Source: Internet
Author: User
Tags ming

Title Description:

As we all know, data stored in a computer is stored in a binary form.
One day, after Xiao Ming learned c, he wanted to know what kind of a number is a type unsigned int, and what the binary string stored in the computer looks like.
Can you help Xiao Ming? And, Xiaoming does not want the binary string in front of meaningless 0 strings, that is, to remove the leading 0.

Input:

The first line, a number T (t<=1000), represents the number of numbers required below.
Next there is a T line, each line has a number n (0<=n<=10^8), which represents the required binary string.

Output:

Outputs a total of T-lines. The binary string that is evaluated for each line of output.

Sample input:
523535262456275989835
Sample output:
101111000010111101001000000110110111101001111110001101010001011





#include <iostream>using namespacestd;voidPrintbinary (intval) {    intarry[1024x768]; intk=0; if(val==0) {cout<<0; }    Else    {     while(val) {arry[k++]=val%2; Val=val/2; }         for(inti=k-1; i>=0; i--) {cout<<Arry[i]; }} cout<<Endl;}intMain () {intcount; CIN>>count;  for(intI=0; i<count;i++)    {        intnum; CIN>>num;    Printbinary (num); }    return 0;}

Or

#include <stdio.h>#include<stdlib.h>intarray[10001]; intMain () {intn,i,k; unsignedintN;  while(SCANF ("%d", &n)! =EOF) {           while(n--) {k=0; scanf ("%u",&N); if(n = =0) {printf ("0\n"); }              Else            {                   while(n) {array[k+ +] = n%2; N= N/2; }                   for(i = k-1; I >=0; i--) {printf ("%u", Array[i]); } printf ("\ n"); }          }      }      return 0; }  

Topic 1473: Binary number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.