Skip to content

Instantly share code, notes, and snippets.

@ha1f
Created March 18, 2024 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ha1f/3d3dc760a0160cbbbfc9aa81c91a9934 to your computer and use it in GitHub Desktop.
Save ha1f/3d3dc760a0160cbbbfc9aa81c91a9934 to your computer and use it in GitHub Desktop.
/// 指定した桁数で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