473,732 Members | 2,043 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 34737

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
3083
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
1833
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
4123
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
6559
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
3785
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
30211
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
12617
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
3293
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
5166
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
5339
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
8773
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
9306
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9234
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
9180
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6733
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6030
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
4548
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
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.