Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6227853
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:17:27+00:00 2026-05-24T09:17:27+00:00

BigInteger bx=new BigInteger(3806908688); byte x[]=new byte[4]; String s=bx.toString(10); System.out.println(string: +s); x=s.getBytes(); int l=0,i=0; l

  • 0
BigInteger bx=new BigInteger("3806908688");

byte x[]=new byte[4];

String s=bx.toString(10);

System.out.println("string: "+s);

x=s.getBytes();

int l=0,i=0;

l |= x[i] & 0xFF;

l <<= 8;

l |= x[i+1] & 0xFF;

l <<= 8;

l |= x[i+2] & 0xFF;

l <<= 8;

l |= x[i+3] & 0xFF;

System.out.println(l);

The output is 859320374 instead of 3806908688. Why is this happening when I’m converting a BigInteger into a byte array and printing this byte array as an integer

I also tried using bx.toByteArray() but the result is same

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:17:27+00:00Added an answer on May 24, 2026 at 9:17 am

    If you have to do it manually, do it in a loop:

    // Take care of negative values
    long l = (bigInt.compareTo(BigInteger.ZERO) < 0) ? -1 : 0;
    byte[] array = bigInt.toByteArray();
    for(int i=0; i<array.length-1; i++) {
        l |= array[i] & 0xFF;
        l <<= 8;
    }
    l |= array[array.length-1] & 0xFF;
    

    Alternatively you could just use methods offered by BigInteger:

    int someInt = bigInt.intValue();
    long someLong = bigInt.longValue();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

using Org.BouncyCastle.Math; string p = E7A69EBDF105F2A6BBDEAD7E798F76A209AD73FB466431E2E7352ED262F8C558F10BEFEA977DE9E21DCEE9B04D245F300ECCBBA03E72630556D011023F9E857F; BigInteger P= new BigInteger(p); throwing Exception System.FormatException: Input
Can someone show me how to use the System.Numerics.BigInteger datatype? I tried using this
What would be the best way to convert a 50-digit String to a BigInteger
I'm new to Java and just code a program with BigInteger. public static void
I am trying to reproduce the output of openssl dhparam -out dh1024.pem 1024 command
BigInteger q = new BigInteger(8, 10, new Random()); is giving me random numbers as
import java.math.BigInteger; import java.util.concurrent.*; public class MultiThreadedFib { private ExecutorService executorService; public MultiThreadedFib(final int
Is it possible to do +- operations like this somehow? BigInteger a = new
I have a BigInteger value, let's say it is 282 and is inside the
I believe conversion exactly to BigInteger[] would be optimal in my case. Anyone had

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.