473,383 Members | 1,862 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 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 12288
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.