Problems with using pow

Posted on 2006-11-10
Last Modified: 2006-11-18
I have a small problem with using pow.

public class Main {
    static public int bin2int(int[] array) {
        int value=0;        
        System.out.println("al: "+array.length);
        for(int i = 0, i2 = array.length-1; i < array.length; i++, --i2) {
            value += Math.pow(array[i]*2,i2); ///////////// here the problem is
        System.out.println("dec val: "+value);
        return value;
    public static void main(String[] args) {
        // TODO code application logic here
        int buffer[] = {0,0,0};

gives me:

al: 3
dec val: 1

It should not give me 1 when using pow(0*2,0). How to deal with this?
Question by:m-jansen
  • 2
  • 2
LVL 86

Accepted Solution

CEHJ earned 125 total points
ID: 17914109
>>It should not give me 1 when using pow(0*2,0). How to deal with this?

Yes, x^0=1

Author Comment

ID: 17914140
sorry I got the solution... now
value += array[i]*Math.pow(2,i2);

Author Comment

ID: 17914148
I'll accept your answer anyway
LVL 86

Expert Comment

ID: 17914197

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Exception after setting jdbc session management 2 51
Starting to learn JAVA, 7 59
Java - Why doesn't this JFrame work 3 40
eclipse java  build path 6 43
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now