当前位置:网站首页>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)
边栏推荐
- Record your vulnhub breakthrough record
- 雲計算未來 — 雲原生
- Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.
- Do you feel like you've learned something and forgotten it?
- 剑指Offer07. 重建二叉树
- Implement verification code verification
- Wechat applet - basic content
- error: expected reference but got (raw string)
- Is it OK to open an account for online stock speculation? Is the fund safe?
- Lambda expression
猜你喜欢

LeetCode 0556.下一个更大元素 III - 4步讲完
![[ManageEngine] the role of IP address scanning](/img/dc/df353da0e93e4d936c39a39493b508.png)
[ManageEngine] the role of IP address scanning
![Sword finger offer03 Repeated numbers in the array [simple]](/img/cf/c1ad2f2a45560b674b5b8c11fed244.png)
Sword finger offer03 Repeated numbers in the array [simple]

剑指Offer07. 重建二叉树

2021 autumn Information Security Experiment 1 (password and hiding technology)

Fluent: Engine Architecture

实现验证码验证

Summary of error prone knowledge points: Calculation of define s (x) 3*x*x+1.

Swagger

idea将web项目打包成war包并部署到服务器上运行
随机推荐
Eureka self protection
[download attached] password acquisition tool lazagne installation and use
剑指Offer05. 替换空格
剑指Offer10- I. 斐波那契数列
Flutter: self study system
【ArcGIS自定义脚本工具】矢量文件生成扩大矩形面要素
Wechat applet pages always report errors when sending values to the background. It turned out to be this pit!
网上炒股开户安不安全?谁给回答一下
Self made pop-up input box, input text, and click to complete the event.
Fluent: Engine Architecture
2021 autumn Information Security Experiment 1 (password and hiding technology)
02_ Lock the code, and don't let the "lock" become a worry
Sword finger offer09 Implementing queues with two stacks
Computer version wechat applet full screen display method, mobile phone horizontal screen method.
node的ORM使用-Sequelize
01_ Using the concurrent tool class library, is thread safety safe
(最新版) Wifi分销多开版+安装框架
[embedded] - Introduction to four memory areas
OpenStack节点地址改变
剑指Offer07. 重建二叉树