如何转换的32位整数到64位的值在C

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

我收到编译错误在项目code,其中的情况如下:

I am getting compilation error in a Project Code where the situation is as follows:

typedef unsigned int U32bit; typedef unsigned long long U64bit; U32bit var; U64bit var2; var = function(); /* Function returns a 32-bit value, which is stored in var */ var2 = 100*var1; /* 100*var1 is very Big & can be stored only in U64bit variable */ For the Above Line: var2 = 100*var1

我收到以下编译错误在Solaris上:

I am getting the following Compilation Error on Solaris:

"conversion to non-scalar type requested"

我也曾尝试类型转换:

I have also tried typecasting:

var2 = (U64bit) 100*var1;

这也给出了同样的错误。

This also gives the same error.

推荐答案

标准的固定宽度整数类型 uint32_t的和 uint64_t中,尝试这些。那么该类型的常量可以用定义UINT64_C(100)。

The standard fixed-width integer types in C are uint32_t and uint64_t, try with these. Then a constant of that type can be defined with UINT64_C(100).

要拥有这些类型的,你可能必须添加

To have these types you might have to add

#include <stdint.h>

您包括

更多推荐

如何转换的32位整数到64位的值在C

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

发布评论

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

>www.elefans.com

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