Playing with binary numbers

Hi
I am messing around with classes. I have a card class, which has a rank (2 - 14) and suit (0-3). What I am trying to do, is have a variable in the class cardvalue which holds a binary value for each card, for example, the 2 (2) of hearts (0) would be 0010 00 (I will of course drop the space), I would like it formatted with the first four digits representing the rank, a the second two the suit, for simple comparison with other cards later on in the game.
How do I take the card values and concatenate them together?
Many thanks, Ron

Thanks, I have this:
[code
public class Card
     public enum Rank
     Deuce(2),Three(3),Four(4),Five(5),Six(6),Seven(7), Eight(8), Nine(9), Ten(10), Jack(11), Queen(12), King(13), Ace(14);     
          private final Integer facevalue;
     Rank(Integer facevalue)
     this.facevalue = facevalue;
     public Integer facevalue(){ return facevalue; };
     public enum Suit
          Hearts (0), Clubs(1), Diamonds(2), Spades(3);
          private final Integer suitvalue;
          Suit(Integer suitvalue)
               this.suitvalue = suitvalue;
          public Integer suitvalue(){ return suitvalue; };
     private final Rank rank;
     private final Suit suit;
     private Integer binaryvalue;//value of the card as a 6 bit number, first two suit, second four rank value
     private Card(Rank rank, Suit suit)
this.rank = rank;
this.suit = suit;
//binaryvalue = rank.facevalue & suit.suitvalue;
//binaryvalue = Integer(Integer.toBinaryString( rank.facevalue));
     public Rank rank() { return rank; }
public Suit suit() { return suit; }
public Integer binaryvalue(){ return binaryvalue; }
public String toString() { return rank + " of " + suit; }
]

Similar Messages

  • Recursion with binary numbers

    I need to print out a list of all possiblle binary numbers with as many digits as an int k. For example, if k = 3, it would need to print out 000,001,010,011,100,101,110,111. for k = 2 it is only 00, 01, 10, 11. It is pretty clear that for any k, a recursive technique can be used to solve this problem, but I'm having trouble finding the solution. Please help. Thanks

    You don't need recursion:for (int i = 0, max = 1 << (k - 1); i < max; ++i) {
      print binary i to k digits
    }But a recursive approach would be void increment (int[] data, int digit) {
    if (digit > 0) {
    --digit;
    for (int i = 0; i < 2; ++i) {
      data[digit] = i;
      increment(data, digit);
    } else {
    print contents of data array
    start (int k) { increment(new int[k], k); }Neither code tested.
    Pete

  • Need help with binary numbers

    hey i'm doing some things, but i need a entry of a binary coded number, i know that an hex number is written like 0xFF but how do i put a binary number in an instruction such as:
    byte b
    b="binary number"

    I see what you want to do, but you can only do this with octal and hex. With binary, you would have to do it something like this:
    byte b = Byte.parseByte("01101001", 2); // base-2

  • Issue with automatic numbering of figures in a Technical Document

    Hi everyone, thanks for taking the time to examine my issue. Basically I've inherited a Technical Document which was imported from Quark some years ago and badly cobbled together in IDesign by a novice and I'm bringing it up to standard to make it a bit more usable but do need to retain the conventions within it. It was written as a chaptered document so I've set up the 'chapters' as Sections in InDesign so as to allow for page number variables and a decent ToC etc. I'd like to have the diagram numbers (and associated x-references) automated too, but am floundering a bit with this.
    At the moment all the image captions are set in one paragraph style throughout the document, and I've been playing with the Bullets and Numbering Dialogue within this paragraph style. All the captions are part of the body text or in their own text frames (As opposed to being linked with image metadata or anything like that).
    The  manually written image number format in the document reads like 'Figure Chapter number, colon, Image number,  and then some have (a), (b), or (c). followed by the name)'  eg (worst case) Figure 8:5(c) Sealing the Blahblah Adaptor
    I realise I might have to set up a named list for each 'chapter' because I can't find a way to define the numbered list to show me;
    'Section number, dot, Image number (starting at one then continuing until the next section starts) dot and then if I need it an a, b, c. etc too'
    Not forgetting I have set up the written 'chapters' as Sections in Indesign.
    If I try adding the 'section symbol' to the number field in the bullets and numbering dialogue (inside my paragraph style)  I just get a weird little blue shape that presumably starts a new section rather than identifies the section I've put it in (so that isn't it) and if i try 'Chapter Number' from the number placeholder menu it only ever says '1' because InDesign only allows one 'chapter' per document (and my chapters are actually sections!).
    I do find the coding system for the 'insert special characters or numbered placeholder' really confusing - I'm not familiar with all of them, (and throwing circumflex's and hashtags in doesn't brighten my day) and since I don't know the codes trial and error seemed to be the way forward.  How are we supposed to know the codes - is there a list online somewhere?
    I could manually type the section number in the 'Number' text box in the dialogue (if I make a named list for each chapter) and lift a layer of confusion but surely there's a way to identify a section in a numbered/named list?
    I think I'm really close but it's driving me a bit crazy - I'm sure identifying levels within named lists might be something to do with it, but I can't see how to alter that. Do I need to set up a new paragraph style AND a new named list for each 'chapter' (section)? The alternative could be to split the document up and make a book file so the 'chapters' become real chapters? (I don't want to do this!)
    There's also something in RealWorld InDesign that worries me a bit - it says (even if I had it working the way I want) that it might number unthreaded text frames in the order they were created rather than the order they appear on the page? Um...
    The other thing is I do have a mixture of inline and anchored objects throughout this document so that might mess things up too?! *Sigh!*
    I'm using InDesign 5.5. for Windows. Many thanks for any tips! Hope somone out there is less confused than me!
    kind regards
    Phil

    You're so right!!!
    I really liked the idea of writing a book in pages. Have to write a second edition of something and did not want to use Word2008 on the Mac, because after one year it is still an unstable beast (crashes, crashes).
    So I checked ot Pages 09 - and alas
    * no xreferences
    * no automatic numbering of captions, figures, ...
    Then I asked my publisher for FrameMaker: The answer was: NO longer on the Mac since 2005. I can't believe this. Not a single decent program to write a book on a Mac.
    I don't want to go back to LaTex after 20 years - HELP me somebody
    and show me a few (automatic) workarounds how to play the automatic numbering and Xref tricks in pages.
    Otherwise it's really neat - BUT - nut for writing documents longer than 20 - 30 pages that need off that book like stuff.

  • Operations on very large binary numbers

    Hi guys,
    I'm trying to write a java class for manipulations of very large binary numbers.
    I'm representing the BN internally as boolean[] (array of booleans false for 0 & true for 1).
    I want to write an algorithm for the following operations :
    shifLeft (boolean[] b,int n) : shifting binary number to left by n positions.preferably a circular shift .
    and also the corresponding shiftRight() method.
    can some one guide me on how to implement this ?
    thanks.

    Consider an array of ascii chars....
    array =>   | |a|b|c|d|
    offset = 1
    len = 4In the above there are actually five spots in the
    array but the offset points to the second position in
    the array and the length is 4.
    If I was to extract the value it would be "abcd"
    because of the offset and the length.
    Now a 'shift right' means that if it is "abcd" then
    it should now be "abc" (because the d fell off the
    end.)
    I can do that like this.
    array =>   | |a|b|c|d|
    offset = 1
    len = 3Notice in the above that nothing changed except the
    length. But because the length changed if I
    extracted the value I would get "abc" because the
    offset is 1 and the length is three.
    Notice also that there was no array copying.Are you sure shifting works like that ?
    what I know about left shifting is that the 'd' should be moved left -toghether with a, b, c- and we append a 0 in place of 'd' .
    from what you said the 'd' would be gone , or am I again wrong ?
    it seems i still didn't get any satisfactory answer to this problem...

  • Desperate to play with my ipod

    Guys,
    Five years ago I bought an imac but 2 kids, no time and no money meant I never got the best out of it and I could never afford to upgrade it. To this day I’m still running 10.1.5. I used it for e mail, a few pictures and that’s about it.
    But kids grow up and I’ve just bought myself a shiny new imac and an ipod nano. I can’t tell you how excited I was/am...but Apple have conspired to take the shine off it.
    I plugged my nano in and it tells me I need itunes 7, no bother you may think. I planned to get broadband but intended to continue with dial up for the time being. I searched for the modem port...not there. Nor will it appear. The nice man at Applecare told me they are no more and I’ll have to buy a usb modem. This makes no sense as I will have broadband (hopefully) in a couple of weeks. So I’ve hatched a plan and I need you guys to tell me if it will work or if I’m being daft.
    I figured I could use the old imac to download itunes 7. (Even though it won’t run it). Burn this to a CD, transfer it onto my new imac desktop and click it as if I’d downloaded it.
    Will this work or am I talking of the wrong end?
    Let me know your thoughts as I’m going to burst if I can’t play with my ipod!
    many thanks
    MacDaz
    (Finally, sorry if this in the wrong place, I'm a bit out of practice and it's been re-decorated since I was last here!)

    Although there remains a number of Mac users still on dial-up access, those numbers have steadily declined of late as broadband access has steadily increased. Based on this, Apple decided to no longer include an internal modem with any new Macs (even with portables) and now sells a small external USB modem at a relatively small extra expense if needed.
    This shiny new iMac didn't ship with iTunes 7 already installed?
    I guess not but you should have no problems downloading iTunes 7 and burning the downloaded install file to CD with your old iMac to use to install iTunes 7 on your new iMac.

  • Compare 2 Binary Numbers

    Hi all ,
    suppose I have two arbitrary lenght binary numbers (could be very large binaries).
    exple : 1000111 & 11111110001
    is it possible to compare them using only there 0s & 1s representations.
    i.e I don't want to convert them to base 10 & compare them (probably using BigInteger).
    what I'm looking for is an algorithm that compares 1000111 & 11111110001 only using there 0s & 1s sequences.
    If this is possible how can I implement it ?
    many thanks.

    boolean equal = true;
    for(inti = ar1.length, j=ar2.lenght; i >= 0 && j
    =
    0; i--, j--) {
    if(ar1[ i ]!=ar2[j]) {
    equal = false;
    break;
    } this code will tell you if ar1 & ar2 are equal but
    won't tell you if ar1 <ar2 or ar1>ar2
    how can we tell ar1 > ar2 for exple ?oh my bad.
    well then indeed one would hav to start at the highest bit and embed the "shorter" value with 0's.
    if the representation is in a primitive, eg. long, you cant simply write a < b since java doesnt know unsigned numbers. so either you are carefull enough and only store 31 bits in an int(like leave the highest bit alone) or you check the highest bit first, and then check the remaining.

  • Hp 35s integrating with complex numbers/functions

    Are there any examples of how to integrate a complex function for
    the HP 35s..the manual suggests its possible..but, I can not find one
    example...anywhere... I am just interested in testing.....I do
    not want to break things into parts etc...I just want to try
    e^z for example, where z is complex..any help?
    I have tried xiy, rTheta, x+iy...syntax errors or non existent..funny

    Hi,
    The manual states that complex numbers can be used with EXP(x), but it does not mention anything about using complex numbers for integration. Edit: I missed some text in the manual, see below.
    As far as I can tell it cannot do integration with complex numbers. (The 50g can do this.)
    However, you may get a more definitive answer if you ask your question here:
    http://www.hpmuseum.org/cgi-sys/cgiwrap/hpmuseum/forum.cgi
    EDIT: that forum has moved to a new version:
    http://www.hpmuseum.org/forum/forum-4.html
    Note: I do not work for HP, I just like playing with calculators :-)

  • Iphone and ipad agenda with week numbers

    does anybody now a very good agenda for iphone and ipad with week numbers etc etc

    Yes, meetings recorded in Adobe Connect will not play back on iOS devices.
    Live meetings can be attended with the Adobe Connect Mobile for iOS app, but this app only supports live meetings.
    https://itunes.apple.com/us/app/adobe-connect-mobile-for-ios/id430437503?mt=8

  • How do I use my iPod Touch 4th Generation with air play with my Apple TV?

    Can someone please help me.  I need to find out if my iPod Touch 4th Generation can be used for Air Play with my Apple TV.  When I go to photos I can use Air Play to display them.  But I cannot use airplay for my apps like Facebook, and My games like The Sims.   I am using iOS 6.0.1.  Is that the issue if so, When you be updating the 4th Gen. Touch to be able to use it with the 6.0.2 version.  I beleive Apple can do better with this.  I just purchased my Apple TV yesterday, and I don't want to have to take it back already, because it doesn't work with my iPod 4th Gen.

    Do the games and apps show the AIrPlay option? No all do.
    The second article in my previous reply included:
    From the Videos, iPod, Photos, Music, and YouTube apps on iOS devices, stream videos, music, and photos to an Apple TV (2nd and 3rd generation), or stream music to an AirPort Express or compatible third-party device.
    With iOS 4.3 and later, you can also stream video and audio from a website or a third-party app installed on your iOS device if the developer for the app or website has added AirPlay functionality

  • I was playing with my ipad settings (it's an older model) and noted in the advanced settings of Safari there was a place to view website databases.  When I clicked on this I saw websites.  How do these get there and what does the space amount mean?

    I was playing with my ipad settings and noted in he advanced settings of Safari there was a place to view "website databases".  When I selected this I saw a multitude of websites.
    Can anyone tell me how these get there?  Can a website be posted even if it was never went to?  What does the space amount mean?  For example, 1.5 kb...is this quite a bit?  Would it indicate someone has gone to a site multiple times?
    I share my ipad with my teenage daughter and I'm trying to find out if she's lying to me.  Obviously she's swearing that she has "no idea" how these got there and I'm trying to keep her safe (she's only 14).
    Thanks everyone.
    Concerned Mom

    Think of your PC and the 'temporary internet folder' where it keeps cached copies of web pages or elements off a web page for 'quicker display the next time you visit'. That's pretty much what that folder is. 1.5K is tiny. Probably just a basic page with some text on it. (you might be confusing 1.5K with 1.5 megabyte....megabyte is large...it's roughly 1000 kilobytes, so the 1.5K is a tiny file)
    As far as I know, the only way info gets into that folder is if the browser has been to that site.
    if you have a concern there are browsers out there, McGruff is one i've seen recommended, that allow some degree of parental control and supervision. That or you could passcode lock the iPad or enable the restrictions to turn off some parts of the device to have some control.

  • I have an ipad mini 1st gen 64 gb (wifi only) and i have problem with some of my apps. These apps have lags when you play with them for a few seconds the apps are having lags are call of duty strike team, gta San Andreas and nfs most wanted.pleas help me

    I have an ipad mini 1st gen 64 gb (wifi only) and i have problem with some of my apps. These apps have lags when you play with them for a few seconds the apps are having lags are call of duty strike team, gta San Andreas and nfs most wanted.pleas help me

    I'm going to guess videos buffer for a while also...
    Two possibilities, one is you should close apps on the iPad, the other is your internet speed is not able to handle the demands of a high speed device.
    To close apps:   Double click home button, swipe up to close the apps.
    To solve internet problem, contact your provider.   Basic internet is not enough for video games and movies.   Your router may be old and slow.

  • Help needed with binary data in xml (dtd,xml inside)

    I am using the java xml sql utility. I am trying to load some info into a table.
    my.dtd:
    <!ELEMENT ROWSET (ROW*)>
    <!ELEMENT ROW (ID,JPEGS?)>
    <!ELEMENT ID (#PCDATA)>
    <!ELEMENT DESCRIPTION EMPTY>
    <!ATTLIST DESCRIPTION file ENTITY #REQUIRED>
    <!NOTATION INFOFILE SYSTEM "Files with binary data inside">
    <!ENTITY file1 SYSTEM "abc.jpg" NDATA INFOFILE>
    xml file:
    <?xml version="1.0" standalone="no"?>
    <!DOCTYPE ROWSET SYSTEM "MY.DTD">
    <ROWSET>
    <ROW>
    <ID>1272</ID>
    <DESCRIPTION file="file1"/>
    </ROW>
    </ROWSET>
    I am using the insertXML method to do this. However, the only value that gets loaded is the ID. abc.jpg is in the same directory where I ran the java program.
    Thanks in advance.

    Sorry! wrong dtd. It should read this instead:
    my.dtd:
    <!ELEMENT ROWSET (ROW*)>
    <!ELEMENT ROW (ID,DESCRIPTION?)>
    <!ELEMENT ID (#PCDATA)>
    <!ELEMENT DESCRIPTION EMPTY>
    <!ATTLIST DESCRIPTION file ENTITY #REQUIRED>
    <!NOTATION INFOFILE SYSTEM "Files with binary data inside">
    <!ENTITY file1 SYSTEM "abc.jpg" NDATA INFOFILE>
    null

  • My Game Center won't work on my iPod touch 2nd Gen. It let me sign up but it won't load any of my games and won't let me play with my friends. I don't know why? Any help?

    My ipod touch 2nd Gen let me sign up to game center but it won't load any of my games and won't let me play with my friend. I don't know if it's like this because it is old and slow, or what. Please help me figure this out. Thank You.

    Try:
    - Sign out of Game Center and sign back in
    - Restore from backup. See:                                               
    iOS: Back up and restore your iOS device with iCloud or iTunes
    - Restore to factory settings/new iOS device.                       

  • I have 1 apple id, 2 5S iPhones with separates numbers and both ring when I get a call on one of the numbers. How do I switch that of ?

    I have 1 Apple ID, 2 5S iPhones (1 private/1 work) with separates numbers and both phones ring when I get a call on one of the numbers. How do I switch that of ?

    I realize that my wife could make her own iTunes account; however, she's been using mine for about 2 years now and this hasn't been an issue.  I guess with the Family Sharing she can have access to all of our music and apps now with her own account. 
    I'll have to see if unchecking our emails resolves this issue.

Maybe you are looking for

  • HT201303 how do i remove a credit card from my account

    my itune purchases are being billed to the wrong account.  I need to credit the charges made on the account ending in 1010 and bill to the account that appears in my itunes account. Please advise.  How to I remove credit card ending in 1010 from my a

  • SB Live! WDM occasional droning sound with

    Hi, My SB Li've! WDM came with Dell and works fine. However, when playing certain games that make use of EAX like KOTOR2 or RTW, occassionally the sound will be suddenly replaced by an irritating droning sound that overrides all the background sound

  • Doubt in XI Setting

    when XI is installed ,I think it has inbuilt Adapter engine...Integration Server . when I opened Configuration Builder Screen central adapter engine...Integration Server is not comming how can I get the central adapter engine??do I need to make some

  • Security Manager traceroute ASA 5520

    How can I use Security Manager (3.2) to configure a ASA 5520 to show up in a traceroute, have found a doc on how to do this from the cmd line but would prefer to keep everything in CSM. Mike

  • Issue with OIDM - Error connecting to database -1

    In oidmon.log - "Error connecting to database -1". Config : OID on W2k Install created "ODS" user in the database. I can connect to the DB via SQLPLUS. Any idea what "-1" implies. Any help would be greatly appreciated