Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3759670
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T10:21:09+00:00 2026-05-19T10:21:09+00:00

I have a PostgreSQL 8.4.6 table where player hands with up to 32 cards

  • 0

I have a PostgreSQL 8.4.6 table where player hands with up to 32 cards are represented by 32 bits:

 # \d pref_hand
               Table "public.pref_hand"
 Column |            Type             |   Modifiers
--------+-----------------------------+---------------
 id     | character varying(32)       |
 hand   | bigint                      | not null
 money  | integer                     | not null
 stamp  | timestamp without time zone | default now()
Check constraints:
    "pref_hand_hand_check" CHECK (hand > 0)

(you can see that I’ve already cheated above by using bigint).

My script (please scroll to the bottom to see the rendered cards) works ok on 64-bit CentOS 5.5 Linux. But when I copy it to my 32-bit development VM, it fails.

Here is the code excerpt:

$sth = $db->prepare('select hand, money
                     from pref_hand where id=?
                     order by stamp desc');
$sth->execute(array($id));
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
        print ('<div>');
        for ($i = count($CARDS) - 1; $i >= 0; $i--) {
                $card  = $CARDS[$i];
                $color = (strpos($card, '♥') > 0 ||
                          strpos($card, '♦') > 0 ? 'red' : 'black');

                if (23 == $i || 15 == $i || 7 == $i)
                        print('&nbsp;');

                if ((1 << $i) & $row['hand'])
                        printf('<span class="%s">%s</span>', $color, $CARDS[$i]);
        }
        print ('</div>');
   }

and I think the if ((1 << $i) & $row[‘hand’]) is failing there (sorry, I’ll prepare a reduced test case later if I don’t receive an answer…)

My question is: how to handle those situations best in PHP? I need to cast $row[‘hand’] to unsigned int or long somehow – so that the AND bit-operator works again, but I can’t find those data types in PHP docs.

Thank you! Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T10:21:09+00:00Added an answer on May 19, 2026 at 10:21 am

    You may use GMP to store the number and then test if the card is available via gmp_testbit. Though this obviously requires GMP to be installed (and it usually is not on shared hosting.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using python and postgresql. I have a table with 6 column. One
I have a table in PostgreSQL where the schema looks like this: CREATE TABLE
In PostgreSQL 8.3 database I have bookings table referencing booking_transactions table by ID. So
I have a name of table or view in PostgreSQL database and need to
I have a table in my Postgres database with columns named type, desc, and
I have a PostgreSQL table with the following schema - CREATE TABLE test (
I have a postgresql table containing movements of different items (models) between warehouses. For
say I have a postgresql table with the following values: id | value ----------
I have one table that has 2 fields one( container_id ) for numeric type
I am using PostgreSQL. I have the data in table like: Parent_id Count Read

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.