當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Dart BigInt.toRadixString用法及代碼示例

dart:core 庫中BigInt.toRadixString 方法的用法介紹如下。

用法:

String toRadixString(
   int radix   
)

this 轉換為給定 radix 中的字符串表示形式。

在字符串表示中,'9' 以上的數字使用小寫字母,'a' 為 10,'z' 為 35。

radix 參數必須是 2 到 36 範圍內的整數。

例子:

// Binary (base 2).
print(BigInt.from(12).toRadixString(2)); // 1100
print(BigInt.from(31).toRadixString(2)); // 11111
print(BigInt.from(2021).toRadixString(2)); // 11111100101
print(BigInt.from(-12).toRadixString(2)); // -1100
// Octal (base 8).
print(BigInt.from(12).toRadixString(8)); // 14
print(BigInt.from(31).toRadixString(8)); // 37
print(BigInt.from(2021).toRadixString(8)); // 3745
// Hexadecimal (base 16).
print(BigInt.from(12).toRadixString(16)); // c
print(BigInt.from(31).toRadixString(16)); // 1f
print(BigInt.from(2021).toRadixString(16)); // 7e5
// Base 36.
print(BigInt.from(35 * 36 + 1).toRadixString(36)); // z1

相關用法


注:本文由純淨天空篩選整理自dart.dev大神的英文原創作品 toRadixString method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。