Results 1 to 7 of 7
  1. #1
    ahmed80 is offline Member
    Join Date
    Jan 2011
    Posts
    8
    Rep Power
    0

    Default convert interger value to binary value

    hi '
    i try to convert interger value to binary value using this code.
    String by1 = Integer.toBinaryString(bulkpack.k);
    this function return binary string value.

    i need binary number and after i convert number to binary how i add these values and retun binary value.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    ahmed80 is offline Member
    Join Date
    Jan 2011
    Posts
    8
    Rep Power
    0

    Default Re

    yes
    the function binarytostring return binary value but in string form-

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    I'm confusing now with what you are saying.

    That function returns the string representation of the binary number. Actually there is no binary type specifically.

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    As Eranga said, there is no binary type. There is however a byte type. But also, you can perform binary operations on other data types - shifts, XOR, OR, AND, etc... can all be applied to ints, longs, shorts, etc... So if you simply need to to binary ops, just use the binary ops syntax:
    ^ | >> >>> << and so forth.

    If you are trying to visualize the steps, why not try printing the value of each int as you step through the process - for example:
    Java Code:
    int a = 3;
    int b = 7;
    System.out.println("    "+Integer.toBinaryString(a));
    System.out.println("    "+Integer.toBinaryString(b));
    System.out.println("+ --------------------");
    System.out.println("    "+Integer.toBinaryString(a|b));
    Here is the list of java operators, including bitwise ops:
    Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

    Good luck!
    Last edited by quad64bit; 01-12-2011 at 02:50 PM.

  6. #6
    ahmed80 is offline Member
    Join Date
    Jan 2011
    Posts
    8
    Rep Power
    0

    Default solved

    thanks for help

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Convert String to Binary
    By erakhman in forum New To Java
    Replies: 1
    Last Post: 09-01-2010, 09:25 AM
  2. Replies: 4
    Last Post: 10-26-2009, 11:17 PM
  3. convert binary to images
    By fiqueudrue in forum New To Java
    Replies: 3
    Last Post: 02-12-2009, 10:16 AM
  4. trying to convert an interger to a string
    By matpj in forum New To Java
    Replies: 12
    Last Post: 01-15-2009, 11:08 AM
  5. Use recursion to convert binary to...
    By coco in forum Advanced Java
    Replies: 1
    Last Post: 08-07-2007, 08:46 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
  •