当前位置:网站首页>C语言之二进制与十进制
C语言之二进制与十进制
2022-07-02 06:34:00 【FF小迷糊吖~】
二进制是计算技术中广泛采用的一种数制。二进制数据是用0和1两个数码来表示的数。但是现实生活中,人们使用十进制,可能跟人类有十根手指有关。那么二进制和十进制如何实现转换呢?
问题:
输入4个仅包含0和1的整数(即二进制数),打印与之等价的十进制。
编程要求:
1、按照题目中要求实现进制转换,并借助printf函数输出结果;
2、使用scanf函数进行数据的输入;
3、请严格按照输出效果输出;(影响成绩评定)
4、任务提交代码时需保证其符合行业代码规范,需进行必要的缩进及换行。(影响成绩评定)
运行效果:
请输入仅有4位的二进制数:1101
对应的十进制数是:13
请按任意键继续. . .
#include <stdio.h>
int main(void)
{
int number, result, a, b, c, d;
printf("请输入仅有4位的二进制数:");
scanf("%d", &number);
a = number / 1000 ;
b = number / 100 % 10;
c = number / 10 % 10;
d = number % 10;
printf("对应的十进制数是:%d\n", a * 8 + b * 4 + c * 2 + d);
return 0;
}
边栏推荐
- Activity的创建和跳转
- 每天睡觉前30分钟阅读_day4_Files
- 双非本科生进大厂,而我还在底层默默地爬树(上)
- Don't look for it. All the necessary plug-ins for Chrome browser are here
- [go practical basis] how to install and use gin
- Microservice practice | declarative service invocation openfeign practice
- [staff] time mark and note duration (staff time mark | full note rest | half note rest | quarter note rest | eighth note rest | sixteenth note rest | thirty second note rest)
- Pdf document of distributed service architecture: principle + Design + practice, (collect and see again)
- 每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
- Solution to amq4036 error in remote connection to IBM MQ
猜你喜欢
[staff] time mark and note duration (staff time mark | full note rest | half note rest | quarter note rest | eighth note rest | sixteenth note rest | thirty second note rest)
The channel cannot be viewed when the queue manager is running
【Go实战基础】如何安装和使用 gin
Servlet全解:继承关系、生命周期、容器和请求转发与重定向等
Watermelon book -- Chapter 5 neural network
机器学习之数据类型案例——基于朴素贝叶斯法,用数据辩男女
Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc
Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
Hystrix implements request consolidation
微服务实战|Eureka注册中心及集群搭建
随机推荐
Jd.com interviewer asked: what is the difference between using on or where in the left join association table and conditions
Microservice practice | teach you to develop load balancing components hand in hand
Talk about the secret of high performance of message queue -- zero copy technology
Solutions to Chinese garbled code in CMD window
微服务实战|Eureka注册中心及集群搭建
Dix ans d'expérience dans le développement de programmeurs vous disent quelles compétences de base vous manquez encore?
自定义Redis连接池
Watermelon book -- Chapter 5 neural network
微服务实战|熔断器Hystrix初体验
Chrome浏览器标签管理插件–OneTab
微服务实战|声明式服务调用OpenFeign实践
每天睡觉前30分钟阅读_day4_Files
Microservice practice | declarative service invocation openfeign practice
Servlet全解:继承关系、生命周期、容器和请求转发与重定向等
Taking the upgrade of ByteDance internal data catalog architecture as an example, talk about the performance optimization of business system
Chrome browser plug-in fatkun installation and introduction
聊聊消息队列高性能的秘密——零拷贝技术
Complete solution of servlet: inheritance relationship, life cycle, container, request forwarding and redirection, etc
Typeerror: X () got multiple values for argument 'y‘
Supplier selection and prequalification of Oracle project management system