# Using integers up to 0xFFFFFFFFFFFFFFFF

#### Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

•  Subject
• Author
• Posted on
Hello perl users,

I'm programming a card game were 32 cards are used.

I'd like to represent each of those cards by a bit,
because it makes several things easier for me
(for example I can set a mask for a user,
restricting the cards she can play at some moment)

Unfortunately constants like these:

use constant ALL_CARDS  => 0xFFFFFFFFFFFFFFFF;  # line 46
use constant ALL_CLUBS  => 0x2222222222222222
use constant ALL_DIAMONDS => 0x4444444444444444
use constant ALL_HEARTS => 0x8888888888888888

give me errors:

Integer overflow in hexadecimal number at Const.pm line 46.
Hexadecimal number > 0xffffffff non-portable at Const.pm line 46.

Does anybody have an advice, how could I handle this best?

I'm using perl 5.8.8 at 32-bit OpenBSD 4.3 (and soon 4.4)

Thank you!
Alex

## Re: Using integers up to 0xFFFFFFFFFFFFFFFF

On Tue, 9 Dec 2008 02:49:03 -0800 (PST),

That's quite a bit more than 32 bits. If you want 32 bits, 0xffffffff
should be long enough.

Your line asks for a 64 bit constant. Works on some systems, but
not on all, which is why you get the warning.

Ehm.. use 32 bits when you need 32 bits?

Martien
--
|
Martien Verbruggen           |
first.last@heliotrope.com.au | Curiouser and curiouser, said Alice.
|

## Re: Using integers up to 0xFFFFFFFFFFFFFFFF

A. Farber wrote:

How many bits do you think are set in that constant?

BugBear

## Re: Using integers up to 0xFFFFFFFFFFFFFFFF

Whoops you're right! I need

use constant ALL_CARDS  => 0xFFFFFFFF;

Thank you
Alex

## Re: Using integers up to 0xFFFFFFFFFFFFFFFF

On Tue, 9 Dec 2008 02:49:03 -0800 (PST), "A. Farber"

Well, you already know your problem. But just curious. Here is an alternative:

13 numbers x 4 suites = 52 cards

player has a list of available numbers they can play = 13 bits
player has a list of available suites they can play  = 4 bits

or,

each player has a mask of cards they can play = 20 bits + 32 bits

or,

each player has a mask of cards they can play = 26 bits + 26 bits

clubs/diamonds: A-K = 26 bits from integer1
spades/hearts:  A-K = 26 bits from integer2

or,

each player has a mask of cards they can play = 13 bits + 13 bits + 13 bits + 13
bits

clubs:    A-K = 13 bits from integer1
diamonds: A-K = 13 bits from integer2
spades:   A-K = 13 bits from integer3
hearts:   A-K = 13 bits from integer4

sln