实现一个数据的输入(整形),转变为原码,再变成补码,按照计算机处理过程模拟,开发语言不限,要求可视化模拟细节过程。
1条回答 默认 最新
ProfSnail 2021-03-16 16:58关注给你一个C语言的实现把。
#include <stdio.h> void printBinary(int x){ int l = sizeof(x) * 8; int mask = 0x80000000; for(int i = 0; i < l; i++){ if(x&mask){ printf("1"); } else{ printf("0"); } x=x<<1; } printf("\n"); } void printTrueCode(int x){ if(x < 0){ x = ~x+1; } printf("Print True Code. \n"); printBinary(x); } int main() { int n; scanf("%d", &n); printf("%d\n", n); printTrueCode(n); printf("Print Complemental Code.\n"); printBinary(n); }本来数字在计算机中存储的就是补码形式。如果想要获取他的原码,只需要当这个数字是负数的时候取反加一即可。

试一试~如果问题得到解决,记得采纳一波。
本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 2无用