codeup- hex conversion

1943: hex conversion

Time Limit: 1 Sec  Memory Limit: 32 MB
Submit: 1559  Solved: 579
[Submit][Status][Web Board][Creator:Imported]

Description

A length of up to 30 decimal digits nonnegative integer output is converted into a binary number.

Input

A plurality of sets of data, each of the behavior of a length of not more than 30 decimal nonnegative integer.
(Note that the number is a decimal number 30 may have, instead of the integer 30bits)

Output

Binary number corresponding to each line of output.

Sample Input

985
211
1126

Sample Output

1111011001
11010011
10001100110


. 1 #include <stdio.h>
 2 #include < String .h>
 . 3  
. 4  int main () {
 . 5      char S [ 40 ];
 . 6      int C [ 40 ];
 . 7      the while (Scanf ( " % S " , S)! = the EOF) {
 . 8          int len = strlen (S), I = 0 ;
 . 9          // Q indicating whether to save the first upper borrow high temp 
10          int ANS [ 100 ], NUM = 0 , Q, temp;  
 . 11          // the string first converted to an integer array 
12 is          for( Int K = 0 ; K <len; K ++ ) {
 13 is              C [K] = S [K] - ' 0 ' ;
 14          }
 15          the while (I < len) {
 16              Q = 0 ;
 . 17              ANS [NUM ++] = ( C [len . 1 ])% 2 ;
 18 is              // creates a new array 
. 19              for ( int J = I; J <len; J ++ ) {
 20 is                  TEMP = C [J];
 21 is                  C [J] = (C [J ] + Q) / 2 ;
 22 is                 IF (TEMP% 2 == 0 ) { // determines whether high divisible 
23 is                      Q = 0 ;
 24                  } the else {
 25                      Q = 10 ;
 26 is                  }
 27              }
 28              IF (C [I] == 0 ) I ++ ;
 29          }
 30          for ( int I = num- . 1 ; I> = 0 ; i-- ) {
 31 is              the printf ( " % D ", ans[i]);
32         }
33         printf("\n");
34     }
35     return 0;
36 }

Guess you like

Origin www.cnblogs.com/heyour/p/12149871.html