472,364 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

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 12192
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.

Fix:

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

jacob
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
purpose.
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
purpose.


True.

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

is better.

Also good is

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

jacob
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

1
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;
2
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...
6
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. ...
30
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...
2
by: Yong.D | last post by:
For example: uint64_t TX_TAST = 0x0000000400000000; Can I use it? Best Yong.D
3
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...
15
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...
5
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;...
1
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...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...

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.