Are signed hexdecimal literals possible?

0

I have an array of bitmasks, the idea being to use them to clear a specified number of the least significant bits of an integer that is being used as a set of flags. It is defined as follows:

int clearLow[10]=
{
0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8, 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80, 0xffffff00, 0xfffffe00
};

I recently switching to using gcc 4.8 I have found that this array starts throwing warnings,

warning: narrowing conversion of ‘4294967295u’ from ‘unsigned int’ to ‘int’ inside { } is ill-formed in C++11
etc
etc

Clearly my hexadecimal literals are being taken as unsigned ints and the fix is easy as, honestly, I do not care if this array is int or unsigned int it just needs to have the appropriate bits set in each cell, but my question is this:

Are there any ways to set literals in hexadecimal, for the purposes of simply setting bits, without the compiler assuming them to be unsigned?

c++
c++11
literals
asked on Stack Overflow Mar 26, 2014 by James Matta • edited Mar 26, 2014 by James Matta

2 Answers

4

You describe that you just want to use the values as operands to bit operations. As that is the case, just always use unsigned datatypes. That's the simple solution.

answered on Stack Overflow Mar 26, 2014 by Zuu
2

It looks like you just want an array of unsigned int to use for your bit masking:

const unsigned clearLow[] = {
    0xffffffff, 0xfffffffe, 0xfffffffc, 0xfffffff8, 0xfffffff0, 0xffffffe0, 0xffffffc0, 0xffffff80, 0xffffff00, 0xfffffe00
};
answered on Stack Overflow Mar 26, 2014 by chris • edited Mar 26, 2014 by chris

User contributions licensed under CC BY-SA 3.0