Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Senior Coder
    Join Date
    Dec 2005
    Location
    Slovenia
    Posts
    1,959
    Thanks
    120
    Thanked 76 Times in 76 Posts

    BigIntiger toByteArray

    providing that s = BigIntiger ("60830453755921259750972507581")
    Code:
      String result = new String(s.toByteArray(), "UTF-8");
    result becomes "\u0000čÜ×ČŐÄ"

    why is "\u0000" there, what does it mean ?

    besides I'm unable to reproduce 60830453755921259750972507581 trying with:
    Code:
      String s = "čÜ×ČŐÄ";
      String s1 = new String(s.getBytes(),"UTF-8");
      // or String s1 = new String(s.getBytes());
      byte[] bytes = s.getBytes();
      BigInteger m = new BigInteger(bytes);
    Any thougt welcome.

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    32
    Thanks
    0
    Thanked 2 Times in 2 Posts
    "\u0000" is a null terminator character. If you take the string "\u0000čÜ×ČŐÄ" instead of "čÜ×ČŐÄ" and convert that back to a BigInteger then you will see that you've recreated your original number.

    I can't say exactly why it's there but if you look at the implementation for the String constructor that you're using you should be able to pin it down.


  •  

    Posting Permissions

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