Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Runtime.InteropServices;
- using System.Text;
- namespace Timwi.Temp
- {
- public static class Utils
- {
- struct SixteenBytes
- {
- public byte a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p;
- }
- [StructLayout(LayoutKind.Explicit)]
- struct DecimalReverser
- {
- [FieldOffset(0)]
- public decimal Decimal;
- [FieldOffset(0)]
- public SixteenBytes Bytes;
- }
- private static DecimalReverser _reverser;
- public static decimal ReverseDecimal(decimal original)
- {
- _reverser.Decimal = original;
- SixteenBytes copy = _reverser.Bytes;
- _reverser.Bytes.a = copy.p;
- _reverser.Bytes.b = copy.o;
- _reverser.Bytes.c = copy.n;
- _reverser.Bytes.d = copy.m;
- _reverser.Bytes.e = copy.l;
- _reverser.Bytes.f = copy.k;
- _reverser.Bytes.g = copy.j;
- _reverser.Bytes.h = copy.i;
- _reverser.Bytes.i = copy.h;
- _reverser.Bytes.j = copy.g;
- _reverser.Bytes.k = copy.f;
- _reverser.Bytes.l = copy.e;
- _reverser.Bytes.m = copy.d;
- _reverser.Bytes.n = copy.c;
- _reverser.Bytes.o = copy.b;
- _reverser.Bytes.p = copy.a;
- return _reverser.Decimal;
- }
- }
- static class Program
- {
- static void Main(string[] args)
- {
- Console.OutputEncoding = Encoding.UTF8;
- // Prints 7467534787759564412160049152
- Console.WriteLine(Utils.ReverseDecimal(8472m));
- // Prints -0.40586562448147411255697604608
- Console.WriteLine(Utils.ReverseDecimal((decimal) Math.PI));
- Console.ReadLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement