当前位置:网站首页>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)
边栏推荐
- 十條職場規則
- 低代码平台国际化多语言(i18n)技术方案
- repo Manifest Format
- Togaf certification self-study classic v2.0
- Bert running error: attributeerror: module'tensorflow contrib. tpu' has no attribute 'InputPipelineConfig'
- Apache Mina Development Manual
- Atomic atomic operation
- Use bloc to build a page instance of shutter
- Sword finger offer04 Search in two-dimensional array [medium]
- Integer string int mutual conversion
猜你喜欢

【ManageEngine】IP地址扫描的作用

阿里大于发送短信(用户微服务--消息微服务)
![Sword finger offer04 Search in two-dimensional array [medium]](/img/c4/002c951f8d914aaea4f4133685ebd1.png)
Sword finger offer04 Search in two-dimensional array [medium]

1-2 project technology selection and structure

ES6 standard

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

Sword finger offer05 Replace spaces

Take you to the installation and simple use tutorial of the deveco studio compiler of harmonyos to create and run Hello world?

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

LeetCode 0556. Next bigger element III - end of step 4
随机推荐
(最新版) Wifi分销多开版+安装框架
1-2 project technology selection and structure
wpa_ cli
Dix règles de travail
【嵌入式】---- 内存四区介绍
Adult adult adult
1-1 token
2020-11_ Technical experience set
剑指Offer09. 用两个栈实现队列
ES6 standard
Implement verification code verification
01_ Using the concurrent tool class library, is thread safety safe
公纵号发送提示信息(用户微服务--消息微服务)
写一个简单的nodejs脚本
02_ Lock the code, and don't let the "lock" become a worry
If you can't learn, you have to learn. Jetpack compose writes an im app (II)
Use of atomicinteger
Togaf certification self-study classic v2.0
Take you to the installation and simple use tutorial of the deveco studio compiler of harmonyos to create and run Hello world?
repo Manifest Format