当前位置:网站首页>Swift bit operation exercise
Swift bit operation exercise
2022-07-03 12:38:00 【iWillook】
//
// main.swift
// Ultimate
//
// Created by Mewlan Musajan on 5/7/21.
//
// 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
extension BinaryInteger {
var binaryDescription: String {
var binaryString = ""
var internalNumber = self
for counter in (1...self.bitWidth) {
binaryString.insert(contentsOf: "\(internalNumber & 1)", at: binaryString.startIndex)
internalNumber >>= 1
if counter % 4 == 0 {
binaryString.insert(contentsOf: "_", at:
binaryString.startIndex)
}
}
return "0b" + binaryString
}
}
let pink: UInt32 = 0xCC6699
let redComponent = (pink & 0xFF0000) >> 16
let greenComponent = (pink & 0x00FF00) >> 8
let blueComponent = pink & 0x0000FF
print(pink.binaryDescription)
print(redComponent.binaryDescription)
print(greenComponent.binaryDescription)
print(blueComponent.binaryDescription)
print()
print(pink.binaryDescription)
print("&")
print(Int32(0xFF0000).binaryDescription)
print("===")
print((pink & 0xFF0000).binaryDescription)
边栏推荐
- 239. Sliding window maximum
- temp
- Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
- Public and private account sending prompt information (user microservice -- message microservice)
- [combinatorics] permutation and combination (summary of permutation and combination content | selection problem | set permutation | set combination)
- [ManageEngine] the role of IP address scanning
- Kubectl_ Command experience set
- 剑指Offer07. 重建二叉树
- idea将web项目打包成war包并部署到服务器上运行
- Integer string int mutual conversion
猜你喜欢

2.7 overview of livedata knowledge points
![Sword finger offer03 Repeated numbers in the array [simple]](/img/cf/c1ad2f2a45560b674b5b8c11fed244.png)
Sword finger offer03 Repeated numbers in the array [simple]

1-2 project technology selection and structure

Fluent: Engine Architecture

Use bloc to build a page instance of shutter

Implement verification code verification

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

Prompt unread messages and quantity before opening chat group

云计算未来 — 云原生

剑指Offer09. 用两个栈实现队列
随机推荐
elastic_ L04_ introduction. md
MySQL time zone solution
elastic_ L02_ install
ImportError: No module named examples. tutorials. mnist
Atomic atomic operation
Sword finger offer05 Replace spaces
Fluent: Engine Architecture
Swift5.7 扩展 some 到泛型参数
十條職場規則
How to deploy web pages to Alibaba cloud
Lambda表达式
OpenStack节点地址改变
最新版盲盒商城thinkphp+uniapp
I'm too lazy to write more than one character
2.8 overview of ViewModel knowledge
Slf4j log facade
Introduction to concurrent programming (II)
T430 toss and install OS majave 10.14
repo Manifest Format
Use bloc to build a page instance of shutter