liangjianyi / sundryutilty Goto Github PK
View Code? Open in Web Editor NEW日常开发中为解决某些琐碎问题编写的库
License: MIT License
日常开发中为解决某些琐碎问题编写的库
License: MIT License
每个 BigIntegerToXxx 方法的逻辑都有高度的模式重合,建议 pass-compile IL rewrite 进行 CodeGen。
转换为有符号整数的函数模版:
public static T BigIntegerToXxx(this BigInteger bi) { byte[] bytes = bi.ToByteArray(); if (bytes.Length == **sizeof(T)**) { return BitConverter.To**Xxx**(bytes); } else if (bytes.Length == **sizeof(T)** + 1) { byte[] res = new byte[**sizeof(T)**]; Array.Copy(bytes, res, bytes.Length - 1); return BitConverter.To**Xxx**(res); } else if (bytes.Length < **sizeof(T)**) { byte[] res = new byte[**sizeof(T)**]; Array.Copy(bytes, res, bytes.Length); if (bi.Sign == -1) { for (int i = 0; i < res.Length; i++) { if (res[i] == 0 && i >= bytes.Length) { res[i] = 255; } } } return BitConverter.To**Xxx**(res); } else { throw new ArgumentOutOfRangeException($"bi={bi}", "The bytes length of BigInteger larger than **T**."); } }
转换为无符号整数的函数模版:
public static UT BigIntegerToUXxx(this BigInteger bi) { byte[] bytes = bi.ToByteArray(); if (bytes.Length == sizeof(UT)) { return BitConverter.ToUXxx(bytes); } else if (bytes.Length == sizeof(UT) + 1) { byte[] res = new byte[sizeof(UT)]; Array.Copy(bytes, res, bytes.Length - 1); return BitConverter.ToUXxx(res); } else if (bytes.Length < sizeof(UT)) { byte[] res = new byte[sizeof(UT)]; Array.Copy(bytes, res, bytes.Length); if (bi.Sign == -1) { for (int i = 0; i < res.Length; i++) { if (res[i] == 0 && i >= bytes.Length) { res[i] = 255; } } } return BitConverter.ToUXxx(res); } else { throw new ArgumentOutOfRangeException($"bi={bi}", "The bytes length of BigInteger larger than Int32."); } }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.