当前位置:网站首页>Find the original code, inverse code and complement of signed numbers [C language]
Find the original code, inverse code and complement of signed numbers [C language]
2022-07-07 08:45:00 【Study silently every day】
/* Signed binary number inverse and complement */
#include<stdio.h>
int main()
{
int n,d,i,j;
printf(" Please enter the number of digits of the signed binary number :");
scanf("%d",&n);
int a[n],b[n],c[n];
printf(" Please enter the binary number :");
for(int i=0;i<n;i++) // Enter binary number
{
scanf("%d",&d);
a[i]=d;
}
if(a[0]==0)
{
printf(" The original code of the binary number = Inverse code = Complement code :"); // The original code of a positive number , Inverse and complement are the same
for(int i=0;i<n;i++) //
{
printf("%d",a[i]);
}
}
else if(a[0]==1)
{
printf(" The original code of the binary number :"); // Print the original code of negative numbers
for(i=0;i<n;i++) //
{
printf("%d",a[i]);
}printf("\n");
for(i=1;i<n;i++) // Judge whether the sign bit of the number is 1, Others are 0
{
if(a[i]!=0)
break;
}
if(i==n){ // If it is , Only original code and inverse code
printf(" This number has only original code and complement , There is no inverse code \n");
printf(" The complement of this number is :");
for(j=0;j<n;j+
边栏推荐
猜你喜欢
Teach you how to select PCB board by hand (II)
【踩坑】nacos注册一直连接localhost:8848,no available server
2 - 3 arbre de recherche
【MySQL】数据库进阶之触发器内容详解
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"
Count sort (diagram)
Merge sort and non comparison sort
調用華為遊戲多媒體服務的創建引擎接口返回錯誤碼1002,錯誤信息:the params is error
ncs成都新电面试经验
Opencv learning note 4 - expansion / corrosion / open operation / close operation
随机推荐
详解华为应用市场2022年逐步减少32位包体上架应用和策略
POJ - 3784 Running Median(对顶堆)
MySQL partition explanation and operation statement
Opencv converts 16 bit image data to 8 bits and 8 to 16
Leetcode 1984. Minimum difference in student scores
注解@ConfigurationProperties的三种使用场景
Novice entry SCM must understand those things
National standard gb28181 protocol video platform easygbs adds streaming timeout configuration
联想混合云Lenovo xCloud:4大产品线+IT服务门户
Laravel8 uses passport login and JWT (generate token)
SSM 整合
Low success rate of unit test report
[Yu Yue education] higher vocational English reference materials of Nanjing Polytechnic University
Teach you how to select PCB board by hand (II)
Gson converts the entity class to JSON times declare multiple JSON fields named
Compilation and linking of programs
iptables 之 state模块(ftp服务练习)
You should use Google related products with caution
JEditableTable的使用技巧
[Yugong series] February 2022 U3D full stack class 006 unity toolbar