2017年5月21日 星期日

ITSA 51 - [Problem 1] 十進制轉二進制 - 參考答案

Difficulty: Easy
Ref: ITSA 51 - [Problem 1] 十進制轉二進制
/*******************************************************/
/* [Problem 1] 十進制轉二進制                           */
/* Author: awei0905  [at]  awei0905.blogspot.tw        */
/* Version: 2017/05/21                                 */
/*******************************************************/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

int main()
{
 int n;
 scanf("%d", &n);
 while (n--) {
  int N;
  scanf("%d", &N);
  for (int i = 0; i < 8; i++){
   printf("%d", N & 128 ? 1 : 0);
   N <<= 1;
  }
  printf("\n");
 }
 return 0;
}
Debug: I/O
Bitwise operations 練習題目。
3
127
-128
66
01111111
10000000
01000010

沒有留言:

張貼留言