当前位置:网站首页>二进制的前导的零
二进制的前导的零
2022-04-22 07:44:00 【真题OK撒】
R7-1 二进制的前导的零 (10 分)
计算机内部用二进制来表达所有的值。一个十进制的数字,比如24,在一个32位的计算机内部被表达为00000000000000000000000000011000。可以看到,从左边数过来,在第一个1之前,有27个0。我们把这些0称作前导的零。
现在,你的任务是写一个程序,输入一个整数,输出在32位表达下它前导的零的个数。
输入格式:
一个整数,在32位的整数可以表达的范围内。
输出格式:
一个整数,表达输入被表达为一个32位的二进制数时,在第一个1之前的0的数量。
输入样例:
256
输出样例:
23
import java.util.*;
public class Main{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int x = input.nextInt();
String ans = Integer.toBinaryString(x);
if(x!=0)
System.out.println(32-ans.length());
else
System.out.println(32);
}
}
版权声明
本文为[真题OK撒]所创,转载请带上原文链接,感谢
https://blog.csdn.net/qq_51916951/article/details/123807611
边栏推荐
- GAVL021,GAVL281,AC220V转5V200MA小体积非隔离芯片方案
- shell脚本中ps -ef查询进程PID一直返回异常
- leaflet、cesium加载百度地图,加载自定义样式百度地图
- 101. 对称二叉树(Easy)
- 地图裁剪器,可以将图片裁剪成瓦片数据,主要用途是将高清卫星图像裁剪成瓦片图,可以做离线地图的开发,基于墨卡托坐标
- centos7安装MySQL8.0
- What do you know about the well-known public DNS servers in China
- Network development in WinForm
- 重启redis
- Introduction to smarttablayout
猜你喜欢

235. 二叉搜索树的最近公共祖先(Easy)

Fluent listview loads more

【大话云原生】微服务篇-五星级酒店的服务方式

Simple use of fresco - simpledraweeview

7-34 delete duplicate characters (set usage) & 7-35 count the number of characters (unordered_map)

Machine learning notes - Mathematics in principal component analysis

shell脚本学习笔记——正则表达式

Under the new retail development trend, how to operate and promote the social e-commerce platform?

【论文阅读】【3d目标检测】pvgnet

MATLAB安装产品选择,如何选择需要安装的产品
随机推荐
oracle数据库表空间容量查询及扩容
面经:
指针和数组(操作详解)
VirtualBox虚拟机(甲骨文Oracle VM )
如何用c语言实现【猜数字游戏】
111. 二叉树的最小深度
【大话云原生】微服务篇-五星级酒店的服务方式
客户端与服务器通信项目1
第1关:节点监听机制
Experiment 1: introduction to data science -- data science cognition
MaterialApp
每日一题冲刺大厂第十五天提高组 模
图片旋转
A preliminary understanding of Copula function
Teach you how to realize the pull-down refresh and pull-up load of recyclerview
构造函数与toString
大一的建议
机器学习笔记 - 主成分分析中的数学
用OnLayoutChangeListener的方法解决getTop=0的问题
shell笔记