473,698 Members | 2,243 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

64 bit integer

Jay
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 = 999999999999999 9999;

I am using g++ version 3.3.5(suse 9.3) and have tried both:

unsigned long long test = 999999999999999 999;
and:
uint64_t test = 999999999999999 9999;

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

Dec 7 '05 #1
20 34729

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 = 999999999999999 9999;
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 = 999999999999999 999;
and:
uint64_t test = 999999999999999 9999;

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

Dec 7 '05 #2
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

Dec 7 '05 #3
Jay
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

Dec 7 '05 #4
Jay
I know that the sizes of int, long etc are platform-dependent and I
know that they are not big enough on my platform, I am looking for a
datatype that guarentees me 64bits on any platform. I don't really want
to have to include non-standard libraries, but is there a number class
with arbitrary precision that you would suggest?

Dec 7 '05 #5
Jay <Co******@gmail .com> wrote:
uint64_t test = 999999999999999 9999;

both have this compile error using the command "g++ test.cpp"
test.cpp:5: error: integer constant is too large for "long" type


try:

uint64_t test = 999999999999999 9999LL;
B.

Dec 7 '05 #6
Jay wrote:
I know that the sizes of int, long etc are platform-dependent and I
know that they are not big enough on my platform, I am looking for a
datatype that guarentees me 64bits on any platform.
No such thing with built-in types. C++ compilers can be standard
compliant on 8-bit machines, which implies that no built-in type
*necessarily* supports 64 bits.
I don't really want
to have to include non-standard libraries, but is there a number class
with arbitrary precision that you would suggest?


Check out:

http://www.oonumerics.org/oon/

Cheers! --M

Dec 7 '05 #7
mlimber wrote:
Jay wrote:
I don't really want
to have to include non-standard libraries, but is there a number class
with arbitrary precision that you would suggest?


Check out:

http://www.oonumerics.org/oon/


See also

http://www.swox.com/gmp/

Cheers! --M

Dec 7 '05 #8
unsigned long long a = 999999999999999 9999LLU; is the right way to do
it. If you don't say it's unsigned you get warnings because it's too
large.

That works fine for 64 bit numbers on 32 bit machine.

Dec 7 '05 #9
Jay
Thanks, I just forgot the LLU on the end of a non-int constant

Dec 7 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
3078
by: Tony Johansson | last post by:
Hello! I have some problem with STL function remove I have two classes called Handle which is a template class and Integer which is not a template class. The Integer class is just a wrapper class for a primitive int with some methods. I don't show the Integer class because it will not add any information to my problem. Main is using some STL function Now to my problem.
11
1828
by: nephish | last post by:
Hello there, i need a way to check to see if a certain value can be an integer. I have looked at is int(), but what is comming out is a string that may be an integer. i mean, it will be formatted as a string, but i need to know if it is possible to be expressed as an integer. like this var = some var passed to my script if var can be an integer :
21
4116
by: Frederick Gotham | last post by:
I set about trying to find a portable way to set the value of UCHAR_MAX. At first, I thought the following would work: #define UCHAR_MAX ~( (unsigned char)0 ) However, it didn't work for me. Could someone please explain to me what's going on? I would have thought that the following happens: (1) The literal, 0, whose type is int, gets converted to an unsigned char.
8
6558
by: Candace | last post by:
I am using the following code to pick off each digit of a number, from right to left. The number I am working with is 84357. So for the first iteration it should return the number 7 and for the second iteration it should return the number 5, and so on. But for some reason on the first iteration returns the expected results. Each subsequent iteration returns the number plus 1. In order words, when I run the program I am getting: 7, 6, 4, and...
1
3776
by: charles_gero | last post by:
Hi all, I had a question about the topics in the subject and posted to comp.std.c, but feel it may also be appropriate here. Please excuse this crosspost if it is in bad form. I have a question about whether or not I am interpreting a nuance of the standard correctly, and the implications of said nuance. The sections in the C99 standard (and possibly older standards) that I will reference are as follows (typed out hopefully to avoid...
7
30206
by: laura | last post by:
Hi, I have a variable of type double. I need to know if there is an integer number store there. How can I test that ? I also have a default precision for doing this operation. Many thanks, Laura
9
12612
by: jacob navia | last post by:
Hi I am incorporating 128 Bit integer code into lcc-win and it would be nice to have some code to test this feature. Has anyone here code that uses 128 bit integers? Thanks in advance P.S. This feature is now native in the 64 bit version, i.e.
12
3290
by: lithiumcat | last post by:
Hi, I bothered you a while back about storing integer values in void*. Now in a completely unrelated context, I'm trying to store pointer values in an integer type. So the basic question is, is it possible to convert a pointer into an integer, and then later (but on the same execution environment, ie the program has not exited, thus it's the same architecture, same compiler, same binary representations and so on) retrieve from the
14
5160
by: Default User | last post by:
Hi, If I have three 64 bit integers and I want to do this operation on them: x*y/z Lets say that what we are multiplying by (y) is offset by what we are dividing by (z) so that the final answer will fit in a 64-bit integer. Let me simplify it by using unsigned chars (8 bits):
9
5335
by: tsuyois | last post by:
Hi, I just signed in to this excellent network. I hope I could get some answers to many questions I have in writing C compilers. My first question is: Is "integer demotion" required in ANSI-C? Assumption: - CPU: 32-bit RISC (int = long = 4 bytes, short = 2 bytes, char = 1 byte)
0
8676
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8608
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9161
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8897
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7732
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4370
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.