如何在两个32位整数组合成一个64位的整数。

编程入门 行业动态 更新时间:2024-10-25 02:30:38
本文介绍了如何在两个32位整数组合成一个64位的整数。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个计数寄存器,它是由两个32位的无符号整数,一个用于该值的高32位(最显著字),以及其他的值的低32位(至少显著字)。

什么是C到这两个32位无符号整数组合,然后显示大批的最佳方式?

在特定的:

leastSignificantWord = 4294967295; // 2 ^ 32-1的printf(计数器:%U%U,mostSignificantWord,leastSignificantWord);

这将打印精细。

当数递增到4294967296,我有这样的leastSignificantWord湿巾为0,mostSignificantWord(0开始)现在1.全计数器现在应该读4294967296,但现在它只是显示的是10,因为我米距离leastSignificantWord串联1从mostSignificantWord和0。

我应该

如何使它显示4294967296,而不是10?

解决方案

长长VAL =(久长)mostSignificantWord<< 32 | leastSignificantWord;的printf(%LLI,VAL);

I have a count register, which is made up of two 32-bit unsigned integers, one for the higher 32 bits of the value (most significant word), and other for the lower 32 bits of the value (least significant word).

What is the best way in C to combine these two 32-bit unsigned integers and then display as a large number?

In specific:

leastSignificantWord = 4294967295; //2^32-1 printf("Counter: %u%u", mostSignificantWord,leastSignificantWord);

This would print fine.

When the number is incremented to 4294967296, I have it so the leastSignificantWord wipes to 0, and mostSignificantWord (0 initially) is now 1. The whole counter should now read 4294967296, but right now it just reads 10, because I'm just concatenating 1 from mostSignificantWord and 0 from leastSignificantWord.

How should I make it display 4294967296 instead of 10?

解决方案

long long val = (long long) mostSignificantWord << 32 | leastSignificantWord; printf( "%lli", val );

更多推荐

如何在两个32位整数组合成一个64位的整数。

本文发布于:2023-11-30 01:36:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648282.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:整数   组合   两个   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!