当前位置:网站首页>[C language] PTA 7-47 binary leading zero
[C language] PTA 7-47 binary leading zero
2022-07-29 04:29:00 【LastWhisperw】
Inside the computer, all the values are expressed in binary . A decimal number , such as 24, In a 32 The computer interior of bit is expressed as 00000000000000000000000000011000. You can see , Count from the left , At the first 1 Before , Yes 27 individual 0. We put these 0 Zero called leading .
Now? , Your task is to write a program , Enter an integer , Output in 32 The number of leading zeros in bit expression .
Input format :
An integer , stay 32 An integer can be expressed in a range of bits .
Output format :
An integer , The expression input is expressed as a 32 Bit binary number , At the first 1 Previous 0 The number of .
sample input :
256
No blank lines at the end
sample output :
23
No blank lines at the end
Their thinking : There is i, Make a given number n stay 2^(i-1) and 2^i Between . Find that i, Output 32-i. If n It's a negative number , When storing, the first place is 1.
#include<stdio.h>
#include<math.h>
int main(){
int n;
int i=0;
scanf("%d",&n);
if(n>=0){
while(pow(2,i)<=n){
i++;
}
}
else{
i=32;
}
printf("%d",32-i);
return 0;
}
边栏推荐
- [material delivery UAV] record (ROS + Px4 + yolov5 + esp8266 + steering gear)
- VScode 一键编译和调试
- Record the Niua packaging deployment project
- Multi rotor six axis hardware selection
- 使用容器部署Jenkins
- 9.延迟队列
- Use of construction methods
- Post export data, return
- It won't last for 65 days. It only appears once
- Unity Foundation (3) -- various coordinate systems in unity
猜你喜欢
随机推荐
Back propagation process of manual BP neural network
不会就坚持62天吧 单词之和
C language: typedef knowledge points summary
不会就坚持59天吧 替换单词
Class starts! See how smardaten decomposes complex business scenarios
Introduction and examples of parameters in Jenkins parametric construction
Why is it necessary to scale the attention before softmax (why divide by the square root of d_k)
C language: structure simple syntax summary
Leetcode 686. KMP method of repeatedly superimposing strings (implemented in C language)
JVM (heap and stack) memory allocation
Realize the effect of univariate quadratic equation through JS. Enter the coefficients of a, B and C to calculate the values of X1 and x2
9.延迟队列
Sequence list and linked list
Incubator course design (April 12, 2021)
Labelme cannot open the picture
不会就坚持63天吧 最大的异或
Mongo shell interactive command window
Integration of Nan causes in pytorch training model
Flutter实战-请求封装(二)之dio
Mpc5744p introduction and opensda firmware update