1. Member
Join Date
Apr 2011
Posts
18
Rep Power
0

## Power in java

Hello folks

Each protein sequences can be converted into an integer value by multiplying the ASCII value of its left most character by 1280, that its second left most character by 1281, etc, and then adding up the resulting 4 values (The ASCII value for A = 65, B = 66, C = 67, …, Y = 89.)
For example the integer value for the sequence AFDE is:

I want to convert this calculation to java

(65 x 1283) + (70 x 1282) + (68 x 1281) + (69 x 1280) = 137470533

the numbers

-------------------------------------------------
Java Code:
```   double a = (Aint * (Math.pow( 128,3))) + (Fint * (Math.pow( 128,2))) + (Dint * (Math.pow( 128,1)))+ (Eint * (Math.pow( 128,0)));

System.out.print(a);```

-------------------------------

I got 1.37470533E8

why? any one has idea?
Last edited by someone; 04-19-2011 at 07:25 PM.

2. Um, thats the right answer is it not? Are you looking for it without the power?

3. Member
Join Date
Apr 2011
Posts
18
Rep Power
0
The right answer should be look like this 137470533

4. Right, your problem is not with your math but your formatting. When you use Math.pow your answer will be in Scientific Notation. Look into converting it into an Int.

5. Originally Posted by someone
The right answer should be look like this 137470533
Math.pow(128, 3) != 1283; and nor is this true for the other values.

kind regards,

Jos

6. @JosAH doesn't 1.37470533E8 mean the same thing as 137,470,533?

7. Originally Posted by Dark
@JosAH doesn't 1.37470533E8 mean the same thing as 137,470,533?
Erm, I should put the lights on; I'm getting old, I didn't see it clearly ;-) Or just my deformed mind imagined the number ending in E38 ...

kind regards,

Jos

8. Its been a while since I've dealt with scientific notation, but I was pretty sure he's getting the expected result. He just wants it displayed in a different form.

He should be able to cast it to an int to make it display in long form should he not?

9. Originally Posted by Dark
Its been a while since I've dealt with scientific notation, but I was pretty sure he's getting the expected result. He just wants it displayed in a different form.

He should be able to cast it to an int to make it display in long form should he not?
Yep, that number fits in an int so the cast works.

kind regards,

Jos

10. However, I have no idea whether or not with the formula you will breach 2.3 billion something. If you do, then I suggest casting to long.

11. Originally Posted by Dark
However, I have no idea whether or not with the formula you will breach 2.3 billion something. If you do, then I suggest casting to long.
You can handle only four characters or so in an int range but a long can only handle nine characters. Each characters takes up seven bits so you can only handle characters in the seven bit ASCII range. b.t.w. bitshifts would be more efficient than Math.pow( ... ) operations ...

kind regards,

Jos

12. Member
Join Date
Apr 2011
Posts
18
Rep Power
0
it is the same answer but I think the problem is that I should store it as int not double
any one has idea on how to do that

13. Obviously you didn't read all the replies.

14. Originally Posted by someone
it is the same answer but I think the problem is that I should store it as int not double
any one has idea on how to do that
Either do all the calculations in the int domain (I prefer this method) or cast your result back to the int domain; a simple (int) cast does the job.

kind regards,

Jos

15. Originally Posted by Junky
Obviously you didn't read all the replies.
^This, most definitely this.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•