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 654879
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T22:32:33+00:00 2026-05-13T22:32:33+00:00

Okay, I am working on a card playing program, and I am storing card

  • 0

Okay, I am working on a card playing program, and I am storing card values as hexadecimal digits. Here is the array:

 public int[] originalCards = new int[54]
        {
            0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D,
            0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
            0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D,
            0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D,
            0x50, 0x51
        };

The first digit refers to the suit (1 = spades; 2 = clubs; …. 5 = Jokers)
The second digit is the number of the card (1 = ace, 5 = 5; 13 = K, etc).

I would like to do something like the following:

Pseudocode:

    public int ReturnCard(int num)
    {
        int card = currentDeck[num];
        int suit = card.firsthexdigit;
        int value = card.secondhexdigit;
        return 0;
    }

I don’t need a new method to work on ints, I just included it for clarity’s sake.

Anybody know how to do this in C#?

Edit: Okay, I am using bit shifting as described in one of the answers. I can get the second digit (the suit) just fine, but the first digit keeps coming out as ‘0’. Any idea why?

Edit:edit: okay, works fine now. Thanks guys.

  • 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-13T22:32:33+00:00Added an answer on May 13, 2026 at 10:32 pm

    Here’s an answer using bit fields.

    struct {
        unsigned int suit:4;
        unsigned int value:4;
    } card    = currentDeck[num];
    int suit  = card.suit;
    int value = card.value;
    

    You may need to add in int for padding as either the first or last field to line the bits up properly. Bit fields are normally used to access hardware because hardware registers frequently pack multiple flags into a single byte.

    By the way if you use the bit shift, you want to shift by the number of bits in a hexadecimal digit. One hex digit holds values 0 – 15 or 0 – F, this requires 4 bits not 8. So this should be used:

    int suit = (card & 0xF0) >> 4;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am setting some values at the option page. This is now working okay.
Okay so i am working on a game based on a Trading card game
I'm using the below code for a rollover effect, seems to be working okay!
Okay I'm working in jQuery mobile, and I just put in a PHP script
Okay, so I'm working on a java server for an Apps backend, it must
Okay, I've been working on this for days now and I can't find any
Okay, so I'm working on a memory editor in c++, I have a list
Okay, I've been working through a set of string replacments for bbcode style tags
Okay, so I'm working on an android app. In one of my app's activities
Okay guys, I am working hashmap, using one of my classes as Key. My

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.