若有 unsigned short a = 0x1234,b = 0x5678, 获取a的高字节,b的低字节组合成新值,结果为:0x1278

谁借莪1个温暖的怀抱¢ 2022-08-23 11:58 64阅读 0赞
  1. /*
  2. 若有
  3. unsigned short a = 0x1234,b = 0x5678,
  4. 获取a的高字节,b的低字节组合成新值,结果为:0x1278
  5. */
  6. #include <stdio.h>
  7. int main(void)
  8. {
  9. unsigned a, b;
  10. unsigned t_up, t_down;
  11. printf("enter two unsigned number:\n");
  12. scanf("%x%x", &a, &b);
  13. t_up = a & (~0 << 8);
  14. printf("t_up:%#x\n", t_up);
  15. t_down = b & ~(~0 << 8);
  16. printf("t_down:%#x\n", t_down);
  17. printf("a的高字节和b的低字节合成的值为:%#x\n", t_up + t_down);
  18. return 0;
  19. }
  20. /*
  21. enter two unsigned number:
  22. 1234 5678
  23. t_up:0x1200
  24. t_down:0x78
  25. a的高字节和b的低字节合成的值为:0x1278
  26. */

发表评论

表情:
评论列表 (有 0 条评论,64人围观)

还没有评论,来说两句吧...

相关阅读