当前位置:网站首页>求有符号数的原码、反码和补码【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+边栏推荐
- SSM 整合
- Several ways of lambda used in functions in kotlin (higher-order functions)
- Exercise arrangement 2.10, 11
- JEditableTable的使用技巧
- What is the method of manual wiring in PCB design in 22protel DXP_ Chengdu electromechanical Development Undertaking
- Golang 编译约束/条件编译 ( // +build <tags> )
- MES system is a necessary choice for enterprise production
- Upload an e-office V9 arbitrary file [vulnerability recurrence practice]
- go写一个在一定时间内运行的程序
- FPGA knowledge accumulation [6]
猜你喜欢

let const

MySQL introduction - crud Foundation (establishment of the prototype of the idea of adding, deleting, changing and searching)

Using helm to install rainbow in various kubernetes

Rainbow combines neuvector to practice container safety management
![[paper reading] icml2020: can autonomous vehicles identify, recover from, and adapt to distribution shifts?](/img/ff/81a7b2ec08a6a422a5cf578c1fed13.jpg)
[paper reading] icml2020: can autonomous vehicles identify, recover from, and adapt to distribution shifts?

Rsync remote synchronization

Openvscode cloud ide joins rainbow integrated development system

单场带货涨粉10万,农村主播竟将男装卖爆单?

All about PDF crack, a complete solution to meet all your PDF needs

国标GB28181协议视频平台EasyGBS新增拉流超时配置
随机推荐
[Chongqing Guangdong education] organic electronics (Bilingual) reference materials of Nanjing University of Posts and Telecommunications
测试踩坑 - 当已有接口(或数据库表中)新增字段时,都需要注意哪些测试点?
All about PDF crack, a complete solution to meet all your PDF needs
Data type - integer (C language)
You should use Google related products with caution
Input of mathematical formula of obsidan
Merge sort and non comparison sort
Golang compilation constraint / conditional compilation (/ / +build < tags>)
Interpolation lookup (two methods)
归并排序和非比较排序
POJ - 3784 Running Median(对顶堆)
SSM 整合
南京商品房买卖启用电子合同,君子签助力房屋交易在线网签备案
Three series of BOM elements
Practice of implementing cloud native Devops based on rainbow library app
23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
Gson转换实体类为json时报declares multiple JSON fields named
National SMS center number inquiry
Golan idea IntelliJ cannot input Chinese characters
JS的操作