资源限制
时间限制:1.0s 内存限制:256.0MB
问题描述
输入[-128,127]内的整数,输出其二进制表示。提示,可使用按位与&
输入格式
例:7
输出格式
例:00000111
样例输入
一个满足题目要求的输入范例。
例:
7
样例输出
与上面的样例输入对应的输出。
例:
00000111
数据规模和约定
输入数据中每一个数的范围。
例:0<n,m<100, 0<=矩阵中的每个数<=1000。
——————————————————————————————————————————————————
从数据范围可以看出只需要输出8位的二进制串,第 0 位 到第 7 位
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
for(int i = 0;i < 8;i++) {
int x = n >> (7 - i) & 1;
System.out.print(x);
}
}
}