# convert interger value to binary value

• 01-11-2011, 01:44 PM
ahmed80
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.
• 01-11-2011, 02:47 PM
Eranga
You mean that you want to add two binary numbers?
• 01-11-2011, 02:51 PM
ahmed80
Re
yes
the function binarytostring return binary value but in string form-
• 01-11-2011, 02:56 PM
Eranga
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.
• 01-11-2011, 04:51 PM
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:
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!
• 01-12-2011, 12:13 PM
ahmed80
solved
thanks for help
• 01-21-2011, 12:26 PM
Eranga
Please mark the thread solved then. It's easy to other members, specially for people who has the same issue as you.