如何转换的32位整数到64位的值在C [英] How To Convert a 32-bit Integer into a 64 bit value In C

查看:322
本文介绍了如何转换的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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆