当前位置:网站首页>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)
边栏推荐
- temp
- Everything comes to him who waits
- Implement verification code verification
- RedHat5 安装Socket5代理服务器
- Sword finger offer04 Search in two-dimensional array [medium]
- Sword finger offer10- I. Fibonacci sequence
- Cloud Computing future - native Cloud
- 023 ([template] minimum spanning tree) (minimum spanning tree)
- ES6 standard
- Keep learning swift
猜你喜欢

剑指Offer05. 替换空格

社交社区论坛APP超高颜值UI界面

剑指Offer10- I. 斐波那契数列

Public and private account sending prompt information (user microservice -- message microservice)

Day 1 of kotlin learning: simple built-in types of kotlin

Use Tencent cloud IOT platform to connect custom esp8266 IOT devices (realized by Tencent continuous control switch)

Use bloc to build a page instance of shutter

Sword finger offer05 Replace spaces

LeetCode 0556. Next bigger element III - end of step 4

阿里大于发送短信(用户微服务--消息微服务)
随机推荐
雲計算未來 — 雲原生
Everything comes to him who waits
The difference between lambda and anonymous inner class
regular expression
Atomic atomic operation
Airflow installation jump pit
剑指Offer04. 二维数组中的查找【中等】
2.6 preliminary cognition of synergetic couroutines
2020-09_ Shell Programming Notes
242. Effective letter heteronyms
2021 autumn Information Security Experiment 1 (password and hiding technology)
elastic_ L04_ introduction. md
Flinksql can directly create tables and read MySQL or Kafka data on the client side, but how can it automatically flow and calculate?
Implement verification code verification
2020-11_ Technical experience set
最新版抽奖盲盒运营版
CNN MNIST handwriting recognition
阿里 & 蚂蚁自研 IDE
Shutter: overview of shutter architecture (excerpt)
Cloud Computing future - native Cloud