Results 1 to 15 of 15

Thread: Power in java

  1. #1
    someone is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default 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 06:25 PM.

  2. #2
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Um, thats the right answer is it not? Are you looking for it without the power?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  3. #3
    someone is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    The right answer should be look like this 137470533

  4. #4
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    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.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by someone View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    @JosAH doesn't 1.37470533E8 mean the same thing as 137,470,533?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  7. #7
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Dark View Post
    @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
    cenosillicaphobia: the fear for an empty beer glass

  8. #8
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    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?
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  9. #9
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Dark View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  10. #10
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    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.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by Dark View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    someone is offline Member
    Join Date
    Apr 2011
    Posts
    18
    Rep Power
    0

    Default

    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. #13
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,798
    Rep Power
    7

    Default

    Obviously you didn't read all the replies.

  14. #14
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by someone View Post
    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
    cenosillicaphobia: the fear for an empty beer glass

  15. #15
    Dark's Avatar
    Dark is offline Senior Member
    Join Date
    Apr 2011
    Location
    Camp Lejuene, North Carolina
    Posts
    643
    Rep Power
    4

    Default

    Quote Originally Posted by Junky View Post
    Obviously you didn't read all the replies.
    ^This, most definitely this.
    • Use [code][/code] tags when posting code. That way people don't want to stab their eyes out when trying to help you.
    • +Rep people for helpful posts.

Similar Threads

  1. Replies: 9
    Last Post: 03-07-2011, 04:05 AM
  2. Is it possible to prioritise CPU power in java?
    By 2potatocakes in forum New To Java
    Replies: 6
    Last Post: 10-14-2008, 05:38 PM
  3. [SOLVED] Is it possible to prioritise CPU power in java?
    By 2potatocakes in forum Advanced Java
    Replies: 0
    Last Post: 10-14-2008, 03:56 PM
  4. Power of Java
    By jeffranc in forum JDBC
    Replies: 5
    Last Post: 09-05-2008, 07:14 AM
  5. Power*MatchMaker 0.9.2
    By JavaBean in forum Java Software
    Replies: 0
    Last Post: 11-27-2007, 08:21 PM

Posting Permissions

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