Manisekar Chinnasami

Greenhorn

Posts: 24

posted 10 years ago

A long is 64bit, while an int is 32bit. So, you can represent a long as two ints:

SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6

How To Ask Questions How To Answer Questions

posted 10 years ago

Whether a number is "binary" or not is not a special property of a number. Do you understand what your line of code does?

binVal = Integer.parseInt(Integer.toBinaryString(25));

First, you convert the number 25 to a string of binary digits: "11001"

Then, you interpret this as if this is a decimal number (with the value eleven thousand and one).

This does not "store a number as binary". There is no such thing as "storing a number as binary", or rather, all numbers in the memory of a digital computer are stored as binary!

Anyway, class Long also has a method toBinaryString() and a method parseLong().

Note: If you have a string of binary digits which you want to convert to an Integer or to a Long, use the parseInt(...) or parseLong(...) method with two parameters, and specify 2 for the radix:

[ November 30, 2007: Message edited by: Jesper Young ]

Originally posted by Manisekar Chinnasami:

how can i convert an long value into binary ?? and i have to store it as long ...

(is there any way to store as binary !!! )

binVal = Integer.parseInt(Integer.toBinaryString(25));//for int it is working

Whether a number is "binary" or not is not a special property of a number. Do you understand what your line of code does?

binVal = Integer.parseInt(Integer.toBinaryString(25));

First, you convert the number 25 to a string of binary digits: "11001"

Then, you interpret this as if this is a decimal number (with the value eleven thousand and one).

This does not "store a number as binary". There is no such thing as "storing a number as binary", or rather, all numbers in the memory of a digital computer are stored as binary!

Anyway, class Long also has a method toBinaryString() and a method parseLong().

Note: If you have a string of binary digits which you want to convert to an Integer or to a Long, use the parseInt(...) or parseLong(...) method with two parameters, and specify 2 for the radix:

[ November 30, 2007: Message edited by: Jesper Young ]