当前位置:网站首页>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;
}
边栏推荐
- 《统计学习方法》——第五章、决策树模型与学习(上)
- ClassFile - Attributes - Code
- Supplier selection and prequalification of Oracle project management system
- Watermelon book -- Chapter 5 neural network
- 【Go实战基础】gin 如何绑定与使用 url 参数
- 微服务实战|熔断器Hystrix初体验
- VIM operation command Encyclopedia
- Number structure (C language -- code with comments) -- Chapter 2, linear table (updated version)
- Attributes of classfile
- 每天睡前30分钟阅读Day5_Map中全部Key值,全部Value值获取方式
猜你喜欢
![[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)](/img/7f/2cd789339237b7a881bfed7b7545a9.jpg)
[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)

Microservice practice | teach you to develop load balancing components hand in hand

我服了,MySQL表500W行,居然有人不做分区?
![[go practical basis] how can gin get the request parameters of get and post](/img/fd/66074d157d93bcf20a5d3b37da9b3e.png)
[go practical basis] how can gin get the request parameters of get and post

以字节跳动内部 Data Catalog 架构升级为例聊业务系统的性能优化

数构(C语言)——第四章、矩阵的压缩存储(下)

Chrome video download Plug-in – video downloader for Chrome

机器学习实战:《美人鱼》属于爱情片还是动作片?KNN揭晓答案

Oracle modify database character set

Say goodbye to 996. What are the necessary plug-ins in idea?
随机推荐
Matplotlib剑客行——容纳百川的艺术家教程
概念到方法,绝了《统计学习方法》——第三章、k近邻法
Servlet全解:继承关系、生命周期、容器和请求转发与重定向等
Bold prediction: it will become the core player of 5g
[staff] the lines and spaces of the staff (the nth line and the nth space in the staff | the plus N line and the plus N space on the staff | the plus N line and the plus N space below the staff | the
微服务实战|熔断器Hystrix初体验
Difference between redis serialization genericjackson2jsonredisserializer and jackson2jsonredisserializer
数构(C语言)——第四章、矩阵的压缩存储(下)
Typora安装包分享
Flink-使用流批一体API统计单词数量
Matplotlib swordsman Tour - an artist tutorial to accommodate all rivers
Redis sorted set data type API and application scenario analysis
MySQL error: unblock with mysqladmin flush hosts
[go practical basis] how to customize and use a middleware in gin
西瓜书--第六章.支持向量机(SVM)
Chrome user script manager tempermonkey monkey
View the port of the application published by was
「面试高频题」难度大 1.5/5,经典「前缀和 + 二分」运用题
微服务实战|微服务网关Zuul入门与实战
【Go实战基础】gin 如何设置路由