当前位置:网站首页>求有符号数的原码、反码和补码【C语言】
求有符号数的原码、反码和补码【C语言】
2022-07-07 06:04:00 【每天默默学习】
/*有符号二进制数求反码和补码*/
#include<stdio.h>
int main()
{
int n,d,i,j;
printf("请输入有符号二进制数的位数:");
scanf("%d",&n);
int a[n],b[n],c[n];
printf("请输入该二进制数:");
for(int i=0;i<n;i++) //输入二进制数
{
scanf("%d",&d);
a[i]=d;
}
if(a[0]==0)
{
printf("该二进制数的原码=反码=补码:"); //正数的原码,反码和补码是一样的
for(int i=0;i<n;i++) //
{
printf("%d",a[i]);
}
}
else if(a[0]==1)
{
printf("该二进制数的原码:"); //打印负数的原码
for(i=0;i<n;i++) //
{
printf("%d",a[i]);
}printf("\n");
for(i=1;i<n;i++) //判断该数是否符号位为1,其它各位为0
{
if(a[i]!=0)
break;
}
if(i==n){ //如果是,只有原码和反码
printf("该数只有原码和补码,没有反码\n");
printf("该数的补码为:");
for(j=0;j<n;j+边栏推荐
- Ebpf cilium practice (2) - underlying network observability
- Data type - floating point (C language)
- MES系統,是企業生產的必要選擇
- Input and output of floating point data (C language)
- 测试踩坑 - 当已有接口(或数据库表中)新增字段时,都需要注意哪些测试点?
- About using CDN based on Kangle and EP panel
- 登山小分队(dfs)
- 23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
- [machine learning] watermelon book data set_ data sharing
- [Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
猜你喜欢

数据分析方法论与前人经验总结2【笔记干货】

Input and output of floating point data (C language)

南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案

leetcode134. gas station

关于基于kangle和EP面板使用CDN

JS的操作

Low success rate of unit test report

Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers

The field value in Splunk subquery fuzzy matching CSV is*

Through the "last mile" of legal services for the masses, fangzheng Puhua labor and personnel law self-service consulting service platform has been frequently "praised"
随机推荐
国标GB28181协议视频平台EasyGBS新增拉流超时配置
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
[Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
Ebpf cilium practice (1) - team based network isolation
Opencv learning notes II - basic image operations
Golang 编译约束/条件编译 ( // +build <tags> )
Count sort (diagram)
Tips for using jeditabletable
idea里使用module项目的一个bug
The single value view in Splunk uses to replace numeric values with text
The field value in Splunk subquery fuzzy matching CSV is*
Input of mathematical formula of obsidan
Basic data types and string types are converted to each other
Tronapi-波场接口-源码无加密-可二开--附接口文档-基于ThinkPHP5封装-作者详细指导-2022年7月6日-新手快速上手-可无缝升级tp6版本
如何在快应用中实现滑动操作组件
更改当前文件夹及文件夹下文件日期shell脚本
Opencv learning note 4 - expansion / corrosion / open operation / close operation
Coquette data completes the cloud native transformation through rainbow to realize offline continuous delivery to customers
如何理解分布式架构和微服务架构呢
Opencv learning note 3 - image smoothing / denoising