Re: Need help to convert my C++ codes to Java with GUI
- From: Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx>
- Date: Sun, 24 Feb 2008 14:29:24 GMT
On Sat, 23 Feb 2008 20:46:10 -0800 (PST), Katak
<vampireex@xxxxxxxxxxx> wrote, quoted or indirectly quoted someone who
said :
double exponent = Math.pow(2, power);
result += ((bin.charAt(i) - 48) * (exponent));
power++;
Shift would be more accurate and much much faster.
power = 1;
....
power <<= 1;
or even better just shift (bin.charAt(i) - '0') directly by i.
see http://mindprod.com/jgloss/shift.html
http://mindprod.com/jgloss/binary.html
http://mindprod.com/jgloss/precedence.html
http://mindprod.com/jgloss/bit.html
http://mindprod.com/jgloss/masking.html
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.
- Follow-Ups:
- Re: Need help to convert my C++ codes to Java with GUI
- From: Thomas A. Russ
- Re: Need help to convert my C++ codes to Java with GUI
- References:
- Need help to convert my C++ codes to Java with GUI
- From: vampireex
- Re: Need help to convert my C++ codes to Java with GUI
- From: Roedy Green
- Re: Need help to convert my C++ codes to Java with GUI
- From: Katak
- Re: Need help to convert my C++ codes to Java with GUI
- From: Katak
- Re: Need help to convert my C++ codes to Java with GUI
- From: Jeff Higgins
- Re: Need help to convert my C++ codes to Java with GUI
- From: Katak
- Need help to convert my C++ codes to Java with GUI
- Prev by Date: Re: Need help to convert my C++ codes to Java with GUI
- Next by Date: Re: JTable Row Height Problem
- Previous by thread: Re: Need help to convert my C++ codes to Java with GUI
- Next by thread: Re: Need help to convert my C++ codes to Java with GUI
- Index(es):
Relevant Pages
|