Using integers up to 0xFFFFFFFFFFFFFFFF

A

A. Farber

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_SPADES => 0x1111111111111111
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
 
M

Martien Verbruggen

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

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.
Does anybody have an advice, how could I handle this best?

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

Martien
 
S

sln

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_SPADES => 0x1111111111111111
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top