当前位置:网站首页>求有符号数的原码、反码和补码【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+边栏推荐
- Implementation method of data platform landing
- MES system is a necessary choice for enterprise production
- Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
- let const
- 数据中台落地实施之法
- [kuangbin]专题十五 数位DP
- Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?
- [Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
- Tips for using jeditabletable
- Practice of combining rook CEPH and rainbow, a cloud native storage solution
猜你喜欢

Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms

leetcode135. Distribute candy

Calling the creation engine interface of Huawei game multimedia service returns error code 1002, error message: the params is error

Installation and configuration of PLSQL

Improve the delivery efficiency of enterprise products (1) -- one click installation and upgrade of enterprise applications

IP地址的类别

Compilation and linking of programs

Openvscode cloud ide joins rainbow integrated development system
![Other 7 features of TCP [sliding window mechanism ▲]](/img/ff/c3f52a7b89804acfd0c4f3b78bc4a0.jpg)
Other 7 features of TCP [sliding window mechanism ▲]

Train your dataset with swinunet
随机推荐
[Yu Yue education] basic reference materials of electrical and electronic technology of Nanjing Institute of information technology
如何在图片的目标中添加目标的mask
AVL平衡二叉搜索树
mysql分区讲解及操作语句
联想混合云Lenovo xCloud:4大产品线+IT服务门户
23 Chengdu instrument customization undertaking_ Discussion on automatic wiring method of PCB in Protel DXP
Practice of implementing cloud native Devops based on rainbow library app
Iptables' state module (FTP service exercise)
[Yugong series] February 2022 U3D full stack class 006 unity toolbar
leetcode134. gas station
JEditableTable的使用技巧
About using CDN based on Kangle and EP panel
Rapid integration of authentication services - harmonyos platform
Download and install orcale database11.2.0.4
注解@ConfigurationProperties的三种使用场景
数据中台落地实施之法
iptables 之 state模块(ftp服务练习)
[Chongqing Guangdong education] audio visual language reference materials of Xinyang Normal University
POJ - 3784 Running Median(对顶堆)
[kuangbin]专题十五 数位DP