I have a binary string. Now I need the binary number

Topic.

float f =Float.parseFloat(binaryString)

int binary= Float.floatToIntBits( f)

//isn't working as I had hoped.

Basically I need to do bitwise ops on a binary String. Obviously not possible.

Thanks again.

[313 byte] By [K.TempesTa] at [2007-11-26 17:53:15]
# 1
I may be misunderstanding, but if want to go from say "10100" to the number10100 (base 2) ie 20 (base 10), you can use Integer's parseInt() method. Itallows you to specify the base.
pbrockway2a at 2007-7-9 5:06:14 > top of Java-index,Java Essentials,New To Java...
# 2

That's what I was using and it wasn't working. So let binaryString = "101". Then:

int bin = Integer.parseInt( binaryString, 2)

returns bin as the number 101 or the number 5?

I've been working with parseInt for three weeks and I still get so confused. I know this is very basic sorry but I appreciate it.

K.TempesTa at 2007-7-9 5:06:14 > top of Java-index,Java Essentials,New To Java...
# 3
the API says that would say bin=5.I need bin=101.
K.TempesTa at 2007-7-9 5:06:14 > top of Java-index,Java Essentials,New To Java...
# 4

> the API says that would say bin=5.

> I need bin=101.

Do you really want 101? Why?

What I mean is you start with the string "101" and the parse method returns...

five, V, the number of fingers on one hand (however you want to write that

number). Why do you want a number that's 20 and a bit times as big?

If you do want a hundred and something returned, parse it base 10. (But

stop calling it a binary string, because that's not how you're using it).

pbrockway2a at 2007-7-9 5:06:14 > top of Java-index,Java Essentials,New To Java...
# 5

You mentioned bitwise operations. Try:int bin1 = Integer.parseInt("101", 2); // bin1 is 5

int bin2 = Integer.parseInt("110", 2); // bin2 is 6

// prints 100 - Is this not what you want?

System.out.println(Integer.toBinaryString(bin1 & bin2));

Yes, it is confusing.

pbrockway2a at 2007-7-9 5:06:14 > top of Java-index,Java Essentials,New To Java...