Class OpenRadix
java.lang.Object
cloud.opencode.base.core.OpenRadix
Radix Conversion Utility Class - Binary, octal, decimal, hexadecimal and custom radix conversions
进制转换工具类 - 二进制、八进制、十进制、十六进制和自定义进制转换
Supports conversions between binary, octal, decimal, hexadecimal and custom radixes (2-62).
支持二进制、八进制、十进制、十六进制和自定义进制之间的转换。
Features | 主要功能:
- Decimal to other radix (decimalToBinary, decimalToOctal, decimalToHexadecimal) - 十进制转其他进制
- Other radix to decimal (binaryToDecimal, octalToDecimal, hexadecimalToDecimal) - 其他进制转十进制
- Inter-radix conversion (binaryToHex, hexToBinary, convert) - 进制间转换
- Extended radix support (toBaseExtended, fromBaseExtended for 2-62) - 扩展进制支持
- Formatting (formatBinary, formatHex) - 格式化
- Validation (isBinary, isOctal, isHexadecimal) - 验证
Usage Examples | 使用示例:
// Decimal to binary - 十进制转二进制
String binary = OpenRadix.decimalToBinary(255); // "11111111"
// Binary to hex - 二进制转十六进制
String hex = OpenRadix.binaryToHex("11111111"); // "FF"
// Custom radix - 自定义进制
String base36 = OpenRadix.toBase(1000, 36); // "RS"
// Validation - 验证
boolean valid = OpenRadix.isBinary("1010"); // true
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: Partially (throws on null input) - 空值安全: 部分 (null 输入抛异常)
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic longbinaryToDecimal(String binary) Converts binary to decimal 二进制转十进制static StringbinaryToHex(String binary) Converts binary to hexadecimal 二进制转十六进制static StringGeneral radix conversion 通用进制转换static StringdecimalToBinary(long value) Converts decimal to binary 十进制转二进制static StringdecimalToHexadecimal(long value) Converts decimal to hexadecimal 十进制转十六进制static StringdecimalToHexadecimalLower(long value) Converts decimal to hexadecimal (lowercase) 十进制转十六进制(小写)static StringdecimalToOctal(long value) Converts decimal to octal 十进制转八进制static StringformatBinary(long value) Formats binary (groups of 4) 格式化二进制(每 4 位一组)static StringformatHex(long value) Formats hexadecimal (groups of 2) 格式化十六进制(每 2 位一组)static longConverts any radix to decimal (2-36) 任意进制转十进制(2-36)static longfromBaseExtended(String value, int radix) Converts any radix to decimal (2-62, extended) 任意进制转十进制(2-62,扩展)static longConverts hexadecimal to decimal 十六进制转十进制static StringhexToBinary(String hex) Converts hexadecimal to binary 十六进制转二进制static StringhexToOctal(String hex) Converts hexadecimal to octal 十六进制转八进制static booleanChecks if the string is a valid binary string 验证是否为有效的二进制字符串static booleanisHexadecimal(String str) Checks if the string is a valid hexadecimal string 验证是否为有效的十六进制字符串static booleanChecks if the string is a valid octal string 验证是否为有效的八进制字符串static longoctalToDecimal(String octal) Converts octal to decimal 八进制转十进制static StringoctalToHex(String octal) Converts octal to hexadecimal 八进制转十六进制static StringtoBase(long value, int radix) Converts decimal to any radix (2-36) 十进制转任意进制(2-36)static StringtoBaseExtended(long value, int radix) Converts decimal to any radix (2-62, extended) 十进制转任意进制(2-62,扩展)
-
Method Details
-
decimalToBinary
Converts decimal to binary 十进制转二进制 -
decimalToOctal
Converts decimal to octal 十进制转八进制 -
decimalToHexadecimal
Converts decimal to hexadecimal 十进制转十六进制 -
decimalToHexadecimalLower
Converts decimal to hexadecimal (lowercase) 十进制转十六进制(小写) -
toBase
Converts decimal to any radix (2-36) 十进制转任意进制(2-36) -
toBaseExtended
Converts decimal to any radix (2-62, extended) 十进制转任意进制(2-62,扩展) -
binaryToDecimal
Converts binary to decimal 二进制转十进制 -
octalToDecimal
Converts octal to decimal 八进制转十进制 -
hexadecimalToDecimal
Converts hexadecimal to decimal 十六进制转十进制 -
fromBase
Converts any radix to decimal (2-36) 任意进制转十进制(2-36) -
fromBaseExtended
Converts any radix to decimal (2-62, extended) 任意进制转十进制(2-62,扩展) -
binaryToHex
-
hexToBinary
-
octalToHex
-
hexToOctal
-
convert
-
formatBinary
Formats binary (groups of 4) 格式化二进制(每 4 位一组) -
formatHex
Formats hexadecimal (groups of 2) 格式化十六进制(每 2 位一组) -
isBinary
Checks if the string is a valid binary string 验证是否为有效的二进制字符串 -
isOctal
Checks if the string is a valid octal string 验证是否为有效的八进制字符串 -
isHexadecimal
Checks if the string is a valid hexadecimal string 验证是否为有效的十六进制字符串
-