当前位置:网站首页>How to convert a decimal number to binary in swift
How to convert a decimal number to binary in swift
2022-07-03 12:38:00 【iWillook】

Image Excerpt From: Apple Inc. “The Swift Programming Language (Swift 5.3).” Apple Books. https://books.apple.com/us/book/the-swift-programming-language-swift-5-4/id881256329
//
// main.swift
// Ultimate
//
// Created by Mewlan Musajan on 5/7/21.
//
// Excerpt From: SINKUK KANG “How to convert a decimal number to binary in Swift?” stackoverflow. https://www.xspdf.com/help/51882984.html
extension BinaryInteger {
var binaryDescription: String {
var binaryString = ""
var internalNumber = self
for _ in (1...self.bitWidth) {
binaryString.insert(contentsOf: "\(internalNumber & 1)", at: binaryString.startIndex)
internalNumber >>= 1
}
return "0b" + binaryString
}
}
print(Int8(~0b00001111).binaryDescription)
边栏推荐
- Togaf certification self-study classic v2.0
- 初入职场,如何快速脱颖而出?
- Idea packages the web project into a war package and deploys it to the server to run
- 剑指Offer04. 二维数组中的查找【中等】
- OpenStack节点地址改变
- Sword finger offer05 Replace spaces
- 023 ([template] minimum spanning tree) (minimum spanning tree)
- The latest version of blind box mall thinkphp+uniapp
- Cloud Computing future - native Cloud
- RedHat5 安装Socket5代理服务器
猜你喜欢
随机推荐
初入职场,如何快速脱颖而出?
Airflow installation jump pit
【附下载】密码获取工具LaZagne安装及使用
20. Valid brackets
Sword finger offer07 Rebuild binary tree
十条职场规则
最新版盲盒商城thinkphp+uniapp
双链笔记·思源笔记综合评测:优点、缺点、评价
Swagger
启用MemCached的SASL认证
Is it OK to open an account for online stock speculation? Is the fund safe?
New features of ES6
Shutter widget: centerslice attribute
Flutter 退出登录二次确认怎么做才更优雅?
LeetCode 0556.下一个更大元素 III - 4步讲完
111. Minimum depth of binary tree
Introduction to concurrent programming (II)
2.7 overview of livedata knowledge points
regular expression
145. Post order traversal of binary tree




![Sword finger offer03 Repeated numbers in the array [simple]](/img/cf/c1ad2f2a45560b674b5b8c11fed244.png)



