Forums
New posts
Search forums
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
VB.NET Community
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
C#
C# General Discussion
Can someone port this function from java to c# - note endianness.
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="jargoman, post: 3723, member: 9018"] Well, I came up with the fllowing code. I decided to throw an exception for negative values and hope the code doesn't require the retrieval of big endian negative values. [CODE] public static byte[] bigIntegerToBytes (BigInteger biToConvert, int nbBytesToReturn) { byte[] twosComplement = BigInteger.ToByteArray (); byte[] bytesToReturn = new byte[nbBytesToReturn]; //TODO two's compliments //if ((biToConvert. if (biToConvert.Sign < 0) { // not sure about this one throw new NotImplementedException ("bigIntegerToBytes does not implement the retrieval of negative values"); } // not sure about this either if (twosComplement [twosComplement.Length - 1] == 0) { // there's an empty byte at the end (little endian) to denote a positive number byte[] twosComplementWithoutSign = new byte[twosComplement.Length - 1]; System.Array.Copy (twosComplement, twosComplementWithoutSign, twosComplementWithoutSign.Length); twosComplement = twosComplementWithoutSign; } int nbBytesOfPaddingRequired = nbBytesToReturn - twosComplement.Length; if (nbBytesOfPaddingRequired < 0) { throw new IndexOutOfRangeException("nbBytesToReturn "+nbBytesToReturn+" is too small"); } // big endian //System.Array.Copy(twosComplement, 0, bytesToReturn, nbBytesOfPaddingRequired, twosComplement.Length); // little endian System.Array.Copy(twosComplement, bytesToReturn, twosComplement.Length); return bytesToReturn; } [/CODE] [/QUOTE]
Insert quotes…
Verification
Post reply
C#
C# General Discussion
Can someone port this function from java to c# - note endianness.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.
Accept
Learn more…
Top
Bottom