当前位置:网站首页>求有符号数的原码、反码和补码【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+边栏推荐
- 数据分析方法论与前人经验总结2【笔记干货】
- [machine learning] watermelon book data set_ data sharing
- You should use Google related products with caution
- Implement your own dataset using bisenet
- Several ways of lambda used in functions in kotlin (higher-order functions)
- 2-3查找树
- 2-3查找樹
- Rainbow 5.7.1 supports docking with multiple public clouds and clusters for abnormal alarms
- iptables 之 state模块(ftp服务练习)
- 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"
猜你喜欢

Rainbow combines neuvector to practice container safety management

Input of mathematical formula of obsidan

登山小分队(dfs)

Three series of BOM elements

Opencv learning note 3 - image smoothing / denoising

In go language, function is a type

Fluentd is easy to use. Combined with the rainbow plug-in market, log collection is faster

Input and output of floating point data (C language)

Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?

如何在快应用中实现滑动操作组件
随机推荐
注解@ConfigurationProperties的三种使用场景
[Chongqing Guangdong education] accounting reference materials of Nanjing University of Information Engineering
Input and output of floating point data (C language)
字符串操作
Implement your own dataset using bisenet
路由信息协议——RIP
Interface as a parameter (interface callback)
2-3查找樹
AVL平衡二叉搜索树
IP地址的类别
opencv之图像分割
Rsync remote synchronization
如何在HarmonyOS应用中集成App Linking服务
登山小分队(dfs)
单场带货涨粉10万,农村主播竟将男装卖爆单?
快速集成认证服务-HarmonyOS平台
mysql分区讲解及操作语句
Download and install orcale database11.2.0.4
[machine learning] watermelon book data set_ data sharing
说一个软件创业项目,有谁愿意投资的吗?