computer science lab tips

Discussion in 'OT Technology' started by nur23, Feb 12, 2007.

  1. nur23

    nur23 OT Supporter

    Joined:
    Jun 7, 2006
    Messages:
    487
    Likes Received:
    0
    Location:
    Chi-Town
    For my computer science labe are required to convert from hexidecimal (base 16) to base 2.

    Can someone help me by telling me how i should begin? I sure it starts with some kind of loop, but from then on i'm stumped.


    Code:
    // Lab16st.java
    // The Number System Converter
    // Student Version
     
    import java.util.Scanner;
    public class Lab16st
    {
     public static void main (String args[])   
     {  
      System.out.println("Lab 16 - Number Conversion Program\n\n");
      
      // The next 2 lines are used in all versions.
      System.out.println("ABCD1234 Base-16 converts to " + BaseConverter.fromHexToBin("ABCD1234") + " in Base-2.\n");
      System.out.println("E12B47F5 Base-16 converts to " + BaseConverter.fromHexToBin("E12B47F5") + " in Base-2.\n");
      
      // The next 2 lines are used in the 90-point versions and above.
      // System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToDec("1011111011101111") + " in Base-10.\n");
      // System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToDec("11100100100110110") + " in Base-10.\n");
      // The next line is used in the 95-point versions and above.  
      // System.out.println("1011111011101111 Base-2 converts to " + BaseConverter.fromBinToHex("1011111011101111") + " in Base-16.\n");
      // The next line is used in the 100-point versions and above.  
      // System.out.println("11100100100110110 Base-2 converts to " + BaseConverter.fromBinToHex("11100100100110110") + " in Base-16.\n");
      
      // The next 3 lines are used in the 105 and 110-point versions.
      // System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,5) + " in Base-5.\n");
      // System.out.println("1000 Base-10 converts to " + BaseConverter.fromDecToAny(1000,8) + " in Base-8.\n");
      // System.out.println("200 Base-10 converts to " + BaseConverter.fromDecToAny(200,2) + " in Base-2.\n");
      
      // This last line is only used in the 110 point version.
      // System.out.println("48879 Base-10 converts to " + BaseConverter.fromDecToAny(48879,16) + " in Base-16.\n");
     }
    }
    
    class BaseConverter
    {
        public static String fromHexToBin(String hexNum)
        {
         String binNum = "";
     
          
     
              
         return binNum;
        }
    
     
  2. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    We don't do homework here.

    That said, you can convert from base 16 to base 2 by separating each digit and multiplying it by the appropriate power of 16^x, adding all of the products together, then dividing by powers of 2^x to extract the binary digits.
     
  3. CyberBullets

    CyberBullets I reach to the sky, and call out your name. If I c

    Joined:
    Nov 13, 2001
    Messages:
    11,865
    Likes Received:
    0
    Location:
    BC, Canada/Stockholm, Sweden
  4. nur23

    nur23 OT Supporter

    Joined:
    Jun 7, 2006
    Messages:
    487
    Likes Received:
    0
    Location:
    Chi-Town
    I'm not asking you to do my homework. What i am asking is for some help since i don't know how to start.

    You could at least offer some help.

    To cyber: Google is very inaccurate in terms of finding java coding that must fit the specific requirements of this lab. If there is such a website that offers the help i'm siking, i would gladly follow any links you guys post.
     
  5. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    I did offer some help. I told you the algorithm you need to implement in order to convert hex to binary; in effect, I did the hard part for you.
     
  6. nur23

    nur23 OT Supporter

    Joined:
    Jun 7, 2006
    Messages:
    487
    Likes Received:
    0
    Location:
    Chi-Town
    I understand what you said, yet it will be if no use if i can't put it in terms of coding.

    Will the conversion be sent through a loop? Also, how do i convert characters into integer form, that will be expressed in a base 2 format?
     
  7. Coottie

    Coottie BOOMER......SOONER OT Supporter

    Joined:
    Jun 6, 2006
    Messages:
    32,407
    Likes Received:
    0
    Location:
    OKC
    So you can't google like this:
    java convert char to int

    Ok...I'll try it...let's see what we get:
    hmmm...very first link
    http://forum.java.sun.com/thread.jspa?threadID=571418&messageID=2828674

    Dude google is not unreliable...you simply need to learn to search
     
  8. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    youre not a CS major are you?
     
  9. Sexual Vanilla

    Sexual Vanilla New Member

    Joined:
    May 23, 2005
    Messages:
    6,305
    Likes Received:
    0
    Location:
    South Carolina
    I would hope not.
     
  10. Corp

    Corp OT Supporter

    Joined:
    Sep 11, 2003
    Messages:
    28,201
    Likes Received:
    0
    Location:
    Providence, RI
    please drop out now :ugh:
     
  11. GOGZILLA

    GOGZILLA Double-Uranium Member

    Joined:
    Jan 16, 2003
    Messages:
    10,760
    Likes Received:
    3
    Location:
    Plantation, FL
    yeah i was gonna say go ahead and drop the course and change majors if you are CS/CE but if you're like an IT major or something you could just grind this one course out.
     
  12. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    If you can't translate English into Java -- even with all of the guides to Java programming and keywords available online -- that's your problem. I told you what you need to do, I'd even be willing to spot-check your code if you can't get it to compile, but I'm not going to do the whole damn thing for you.

    It's doubtful that there is a pre-built Hex->Bin function available in the Java STL (or whatever Java calls its STL), because if there were then your professor wouldn't have used it as an assignment. You're just going to have to come up with your own way of storing the input and output; as far as displaying the binary numbers is concerned, you'd be best off to store the output in a text string instead of a number, so you can make it display exactly the way you want.
     

Share This Page