Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Problems with using pow

Posted on 2006-11-10
4
Medium Priority
?
345 Views
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(array[i]+"*2^"+i2+"="+value);
        }
        System.out.println("dec val: "+value);
        return value;
    }
   
    public static void main(String[] args) {
        // TODO code application logic here
        int buffer[] = {0,0,0};
        bin2int(buffer);
    }
}

gives me:

al: 3
0*2^2=0
0*2^1=0
0*2^0=1
dec val: 1

It should not give me 1 when using pow(0*2,0). How to deal with this?
0
Comment
Question by:m-jansen
[X]
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
4 Comments
 
LVL 86

Accepted Solution

by:
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
0
 

Author Comment

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

Author Comment

by:m-jansen
ID: 17914148
I'll accept your answer anyway
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17914197
:-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

609 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