473,704 Members | 2,357 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using uint64_t with GCC

uint64_t i64_BitMask = (uint64_t) (1 << 33) - 1 ;
int a = (i64_BitMask >> 32);
printf ("BitMask %x\n", a);

This produces ffffffff. I'm pretty sure, watching the stages in
debugging, that 1 << 33 is resolving to zero, since it's being shifted
off the MSB of a 32 bit integer.

I am in general having problems with uint64_t with GCC. In particular,
I can't send one to printf and get a sensible output. The shift
operators appear to only work with 32-bit integers. Also, if I have
intermediate steps, it always seems to want to truncate the output to
32-bits. Putting in casts to uint64_t sometimes fixes it, but not
always. What do I do?

(using XCode, Apple's stdint.h)
Jul 23 '05 #1
4 12324
Richard Cavell wrote:

uint64_t i64_BitMask = (uint64_t) (1 << 33) - 1 ;

The problem is that the expression
(1 << 33)
is calculated (as it should) in integer mode, i.e. 32 bits.

The result (zero) is *THEN* cast to uint64_t.


uint64_t i64_BitMask = (uint64_t) ((uint64_t)1 << 33) - 1 ;

Jul 23 '05 #2
jacob navia wrote:

uint64_t i64_BitMask = (uint64_t) ((uint64_t)1 << 33) - 1 ;

You have an unneeded cast there. The left-most cast serves no
Jul 23 '05 #3
Ron Natalie wrote:
jacob navia wrote:

uint64_t i64_BitMask = (uint64_t) ((uint64_t)1 << 33) - 1 ;

You have an unneeded cast there. The left-most cast serves no


uint64_t i64_BitMask = ((uint64_t)1 << 33) - 1 ;

is better.

Also good is

uint64_t i64_BitMask = (1LL << 33) - 1 ;

Jul 23 '05 #4
i don't know why you need shifts, in some cases <bitset> is more
elegant IMHO

Jul 23 '05 #5

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

Similar topics

by: Jhy-Chun Wang | last post by:
Hi, I have a c++ extension that does thing like: extern "C" static PyObject * nasUtil_access_cmd(PyObject *self, PyObject *args) { uint64_t paddr; uint64_t data;
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using X509Certificate ( *.cer file ) so that it can be used to email as attachment. The real part is Encrypting using X509Certificate and CryptoServiceProvider.
by: Hamburgpear | last post by:
Dear C/C++ fellow user, How can I declare integer such that I can compute factorial of number larger than 13, which can't return a correct result as it is larger than the integer limit in C. Thanks in advance Hamburgpear
by: junky_fellow | last post by:
I was looking at the source code of linux or open BSD. What I found that lots of typedefs were used. For example, consider the offset in a file. It was declared as off_t offset; and off_t is typedefed as typedef long off_t; I wanted to know what advantage do we get by typedefs ? Why we did not declare
by: Yong.D | last post by:
For example: uint64_t TX_TAST = 0x0000000400000000; Can I use it? Best Yong.D
by: JDeats | last post by:
I have some .NET 1.1 code that utilizes this technique for encrypting and decrypting a file. http://support.microsoft.com/kb/307010 In .NET 2.0 this approach is not fully supported (a .NET 2.0 build with these methods, will appear to encrypt and decrypt, but the resulting decrypted file will be corrupted. I tried encrypting a .bmp file and then decrypting, the resulting decrypted file under .NET 2.0 is garbage, the .NET 1.1 build works...
by: Konstantin Andreev | last post by:
I'm almost sure I've found bad bug, but for a while I can't neither confirm nor reject this. If anybody could make an independent test on it's own system, I'd appreciate it very much. The possible bug is: **************** *** DB2 refuses DEVICE containers bigger than 4Gb. *** ****************
by: seung | last post by:
Hi, I'm trying to use uint64_t by #including stdint.h in C on 32-bit machine. However, I can't seem to get the right value for shifting, for example: for(i = 0; i < 64; i++) { c = 1 << i; printf(" %d : %x\n", i, c);
by: Przemyslaw Koprowski | last post by:
This is the question about what the statndard of C++ says. Unfortunately I don't have access to the standard, so I decided to ask here. Is the type uint64_t accepted by the current standard? If not, is it expected for the incomming version? If this is the case, does the standard says how to enter uint64_t constants espacially if it happens that uint64_t is strictly bigger than unsigned long?
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,...
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...
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,...
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...
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...
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...
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();...
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
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.