美文网首页
输出补码的第二种方式

输出补码的第二种方式

作者: wangxn | 来源:发表于2016-03-22 09:28 被阅读0次

#include <stdio.h>
#include <stdlib.h>

//模拟一个字节的数据 typedef struct _bitStruct{ unsigned char b1:1; unsigned char b2:1; unsigned char b3:1; unsigned char b4:1; unsigned char b5:1; unsigned char b6:1; unsigned char b7:1; unsigned char b8:1; }bitStruct;

int main(void){ //获得4个字节的空间 bitStruct * pBit = (bitStruct *)malloc(sizeof(bitStruct) *4); //将指针强转为int 的型的指针, 模拟int型数据的情况 int * pInt = (int *)pBit; //共享空间 printf("%s\n", "please enter a number for test:"); scanf("%d", pInt); int i; //因为在内存中 数据存储的字节存储是高位字节在前,低位字节在后,所以要倒着打印数据 for(i = 3; i>=0;i--){ //因为在内存中 数据存储是的位也是高位在前,低位在后,所以要倒着打印数据 printf("%d%d%d%d %d%d%d%d ", pBit[i].b8, pBit[i].b7, pBit[i].b6, pBit[i].b5, pBit[i].b4, pBit[i].b3, pBit[i].b2, pBit[i].b1); } printf("\n"); return 0; }

相关文章

  • 输出补码的第二种方式

    #include #include //模拟一个字节的数据 typedef struct _bitStruct{...

  • PHP-几行代码翻转链表

    声明结构 输出 第一种翻转方式 (递归) 第二种翻转方式 (循环) 输出

  • 输出补码的第一种方式

    #include #include char * getComplement(int num, int len)...

  • int数字的表示

    在计算机中int型数字使用补码的形式在存储。首先说明补码的计算方式。正数和零的补码就是他们本身。负数的补码是符号位...

  • 计算机为什么要使用原码、反码、补码

    1. 什么是原码、反码、补码 先看一个例子: +1和-1的原码、反码、补码的表示 原码、反码、补码的计算方式如下:...

  • 学习Python3 进程,这一篇就够了

    第一种方式:使用os模块中的fork方式实现多进程 输出结果: 第二种方法:使用multiprocessing模块...

  • 进制关系

    各进制的形式 正数的原码、反码、补码相同 负数的反码为原码各位取反,补码为反码+1 计算机的底层都是以补码的方式来...

  • 原码、反码、补码

    数值在计算机中是以补码的方式存储的,在探求为何计算机要使用补码之前, 让我们先了解原码, 反码和补码的概念。 对于...

  • 原码、反码、补码

    数值在计算机中是以补码的方式存储的,在探求为何计算机要使用补码之前, 让我们先了解原码, 反码和补码的概念。 对于...

  • 原码,反码,补码

    数值在计算机中是以补码的方式存储的,在探求为何计算机要使用补码之前, 让我们先了解原码, 反码和补码的概念。 对于...

网友评论

      本文标题:输出补码的第二种方式

      本文链接:https://www.haomeiwen.com/subject/vstllttx.html