64位整数

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

您好,我相信这有一个快速简便的解决方案,但我找不到 吧。 我需要存储19' '9'是一个整数,这意味着我需要一个无符号的64 位 整数。 在Visual Studio中的代码如下: __int64 test = 9999999999999999999; 我使用g ++版本3.3.5(suse 9.3)并尝试过两种方法: unsigned long long test = 999999999999999999; 和: uint64_t test = 9999999999999999999; 两者都使用命令g ++ test.cpp进行编译错误 test.cpp:5:错误:整数常量对于long而言太大了类型 我打算包含一些或不通过g ++的选项,或者 有另一种方法可以做64位整数存储? 感谢您的帮助

解决方案

Jay写道:

您好,我确信这有一个快速简便的解决方案,但我找不到它。 我需要以整数存储19''9',这意味着我需要一个无符号的64位整数。在Visual Studio中,代码为: __int64 test = 9999999999999999999; 双下划线是赠品,这不是C ++,而是一个 Microsoft 扩展名。 我使用g ++版本3.3.5(suse 9.3)并尝试过两种方法: unsigned long long test = 999999999999999999; 和: uint64_t test = 9999999999999999999; 使用命令g ++ test.cpp进行编译错误测试错误:5:错误:整数常量对于long而言太大了type

合理的,按照标准规则它可能确实拒绝代码。如果 你需要GCC扩展到C ++,你应该在GCC小组中询问。 HTH, Michiel Salters

Jay写道:

您好,我确信这有一个快速简便的解决方案,但我找不到它。 我需要存储19''9'的整数,这意味着我需要一个无符号的64位整数。

[snip] 或者你可以使用任意精度的数字类。各种内置整数类型的大小取决于平台,因此你需要查看你的操作系统/编译器文档。 干杯! --M

所以没有使用扩展名就没有办法在C ++中这样做吗? 如果这是错误的这个问题的小组,你碰巧知道 哪个群体更合适? 谢谢

Hello, I am sure this has a quick and easy solution but I can''t find it. I need to store 19 ''9''s in an integer which means i need an unsigned 64 bit integer. in Visual Studio the code would be: __int64 test = 9999999999999999999; I am using g++ version 3.3.5(suse 9.3) and have tried both: unsigned long long test = 999999999999999999; and: uint64_t test = 9999999999999999999; both have this compile error using the command "g++ test.cpp" test.cpp:5: error: integer constant is too large for "long" type Am I forgeting to include something or not passing an option to g++, or is there another way to do 64 bit integer storage? Thank you for your help

解决方案

Jay wrote:

Hello, I am sure this has a quick and easy solution but I can''t find it. I need to store 19 ''9''s in an integer which means i need an unsigned 64 bit integer. in Visual Studio the code would be: __int64 test = 9999999999999999999; The double underscore is a giveaway that this isn''t C++, but a Microsoft extension. I am using g++ version 3.3.5(suse 9.3) and have tried both: unsigned long long test = 999999999999999999; and: uint64_t test = 9999999999999999999; both have this compile error using the command "g++ test.cpp" test.cpp:5: error: integer constant is too large for "long" type

Reasonable, by the standard rules it may indeed reject the code. If you need an GCC extension to C++, you should ask in a GCC group. HTH, Michiel Salters

Jay wrote:

Hello, I am sure this has a quick and easy solution but I can''t find it. I need to store 19 ''9''s in an integer which means i need an unsigned 64 bit integer.

[snip] Or you could use a number class with arbitrary precision. The sizes of the various built-in integral types are platform-dependent, so you''ll want to check with your OS/compiler documentation. Cheers! --M

So is there no way to do this in C++ without using an extension? If this is the wrong group for this question, do you happen to know which group would be more appropriate? Thank you

更多推荐

64位整数

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

发布评论

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

>www.elefans.com

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