Created
March 18, 2024 07:12
-
-
Save ha1f/3d3dc760a0160cbbbfc9aa81c91a9934 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 指定した桁数で2進数を表示する、0埋め | |
func formatBinary8(_ num: UInt8, digits: Int = 8) -> String { | |
let s = String(num, radix: 2) | |
return s.count < digits | |
? String(repeating: "0", count: digits - s.count) + s | |
: s | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment