Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How should a System.Decimal be converted to BigEndian format for sending to a bigendian server?

IIUC the System.Decimal representation is an array of 32bit words in this order:

lo mid hi flags

From a little endian representation, to serialise for a System.Decimal recipient on a big endian server, is it necessary to:

  1. Preserve lo mid and hi order
  2. Reverse the bytes in each lo/mid/hi integer
  3. Preserve the flags integer byte ordering

I guess this means using GetBits to get the words , reverse each integer apart from the 4th element, and re-assemble the bytes to send to the server?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

The Decimal(int[]) constructor is documented as expecting the integers in a specific order,

bits is a four-element long array of 32-bit signed integers.

bits [0], bits [1], and bits [2] contain the low, middle, and high 32 bits of the 96-bit integer number.

bits [3] contains the scale factor and sign

which wouldn’t change on an BigEndian platform.

If the Decimal is layed out in memory differently, that’s handled internally.

Of course you may need to convert the Int32’s to BigEndian if you’re not using a standard framework like protocol buffers or json.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading