当前位置:网站首页>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)
边栏推荐
- Applet wxss introduction
- Recovery of website address and method of Amazon account login two-step verification failure caused by mobile phone number becoming empty
- Flutter Widget : KeyedSubtree
- init. RC service failed to start
- 阿里大于发送短信(用户微服务--消息微服务)
- Is it safe to open an account for online stock speculation? Who can answer
- Flutter 退出登录二次确认怎么做才更优雅?
- Pytext training times error: typeerror:__ init__ () got an unexpected keyword argument 'serialized_ options'
- [combinatorics] permutation and combination (example of permutation and combination)
- (最新版) Wifi分销多开版+安装框架
猜你喜欢

Display time with message interval of more than 1 minute in wechat applet discussion area

2.8 overview of ViewModel knowledge

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

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

实现验证码验证

2.7 overview of livedata knowledge points

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

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

Fluent: Engine Architecture

阿里大于发送短信(用户微服务--消息微服务)
随机推荐
239. Sliding window maximum
Lambda expression
Everything comes to him who waits
【ManageEngine】IP地址扫描的作用
Oh my Zsh + TMUX installation
最新版抽奖盲盒运营版
Unicode查询的官方网站
RedHat5 安装Socket5代理服务器
Itext7 uses iexternalsignature container for signature and signature verification
MySQL time zone solution
error: expected reference but got (raw string)
Sqoop1.4.4原生增量导入特性探秘
Flutter: self study system
Develop plug-ins for idea
The difference between lambda and anonymous inner class
Shutter widget: centerslice attribute
257. All paths of binary tree
网上炒股开户安不安全?谁给回答一下
JVM内存模型
Display time with message interval of more than 1 minute in wechat applet discussion area