当前位置:网站首页>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;
}
边栏推荐
- Supplier selection and prequalification of Oracle project management system
- Probability is not yet. Look at statistical learning methods -- Chapter 4, naive Bayesian method
- What are the differences between TP5 and laravel
- Chrome user script manager tempermonkey monkey
- [go practical basis] how to install and use gin
- Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
- 微服务实战|Eureka注册中心及集群搭建
- MySQL error: unblock with mysqladmin flush hosts
- 分布式服务架构精讲pdf文档:原理+设计+实战,(收藏再看)
- 数构(C语言--代码有注释)——第二章、线性表(更新版)
猜你喜欢

Idea view bytecode configuration

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

Watermelon book -- Chapter 6 Support vector machine (SVM)

定时线程池实现请求合并
![[go practical basis] how to install and use gin](/img/0d/3e899bf69abf4e8cb7e6a0afa075a9.png)
[go practical basis] how to install and use gin

每天睡前30分钟阅读Day6_Day6_Date_Calendar_LocalDate_TimeStamp_LocalTime

十年開發經驗的程序員告訴你,你還缺少哪些核心競爭力?
![[go practical basis] how to customize and use a middleware in gin](/img/fb/c0a4453b5d3fda845c207c0cb928ae.png)
[go practical basis] how to customize and use a middleware in gin

Required request body is missing:(跨域问题)

聊聊消息队列高性能的秘密——零拷贝技术
随机推荐
分布式服务架构精讲pdf文档:原理+设计+实战,(收藏再看)
AMQ 4043 solution for errors when using IBM MQ remote connection
ClassFile - Attributes - Code
Data type case of machine learning -- using data to distinguish men and women based on Naive Bayesian method
Microservice practice | Eureka registration center and cluster construction
京东面试官问:LEFT JOIN关联表中用ON还是WHERE跟条件有什么区别
Beats (filebeat, metricbeat), kibana, logstack tutorial of elastic stack
Watermelon book -- Chapter 5 neural network
记录下对游戏主机配置的个人理解与心得
企业级SaaS CRM实现
Idea view bytecode configuration
【Go实战基础】如何安装和使用 gin
Matplotlib剑客行——没有工具用代码也能画图的造型师
Number structure (C language) -- Chapter 4, compressed storage of matrices (Part 2)
Timed thread pool implements request merging
Chrome用户脚本管理器-Tampermonkey 油猴
Servlet全解:继承关系、生命周期、容器和请求转发与重定向等
Activity的创建和跳转
Microservice practice | declarative service invocation openfeign practice
微服务实战|熔断器Hystrix初体验