Problems with using pow

Posted on 2006-11-10
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
LVL 86

Accepted Solution

CEHJ earned 250 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month8 days, 8 hours left to enroll

764 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