Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23

Thread: binary

  1. #21
    Engineer is offline Member
    Join Date
    Aug 2010
    Location
    Egypt
    Posts
    34
    Rep Power
    0

    Default

    Quote Originally Posted by Vinod Mukundan View Post
    By last number you mean 1 out of 1010 ??? then jus try

    bin.charAt(0);
    1110
    +
    0101
    -------------
    10011
    i need to represent the result in four bit
    so i should delet the last element (1)
    to be
    0011
    and i need to print the last number(1) to show me if it delet (1)or(0):)
    thankssssssssssssssssssssssssssssssssssssssssss:)

  2. #22
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,309
    Blog Entries
    7
    Rep Power
    20

    Default

    Why don't you people create a little class ALU with a single constructor public ALU(int width), where the parameter is the number of bits in its register. (Internally you can use a long and restrict the width parameter <= 32). A few simple methods, say add( ... ), sub( ... ) and toString() can do the rest of the job.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #23
    Join Date
    Jul 2010
    Location
    India
    Posts
    58
    Rep Power
    0

    Default

    Quote Originally Posted by Engineer View Post
    1110
    +
    0101
    -------------
    10011
    i need to represent the result in four bit
    so i should delet the last element (1)
    to be
    0011
    and i need to print the last number(1) to show me if it delet (1)or(0):)
    Ok

    Java Code:
     int len = bin.length();
            if(len>limit) {
               System.out.println("Deleting items "+bin.substring(0, len-limit)); 
               bin = bin.substring(len-limit, bin.length());
            }
            System.out.println(bin);
    Ok here your limit is 4.... SO pass 4 .. just wrote generic...


    Hi JOSAH,,
    I agree withg that but right now am helping him out with just the logical part :)
    _______________________________________________
    give me beans .........

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Binary
    By THEAniKan in forum Entertainment
    Replies: 1
    Last Post: 01-06-2012, 10:14 AM
  2. Binary IO help
    By kosok in forum New To Java
    Replies: 2
    Last Post: 12-25-2008, 07:58 AM
  3. get binary value
    By rushenas in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 01:51 PM
  4. binary conversion
    By thamizhisai in forum New To Java
    Replies: 3
    Last Post: 04-29-2008, 11:55 AM
  5. Binary Addition
    By Deo Favente in forum Advanced Java
    Replies: 11
    Last Post: 04-24-2008, 05:34 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •