Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
元組み込みエンジニアがKotlinのビット演算を使ってみた
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kenta Harada
September 25, 2024
Programming
87
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
元組み込みエンジニアがKotlinのビット演算を使ってみた
「集まれKotlin好き!Kotlin愛好会 vol. 54@株式会社TOKIUM」で発表した資料です。
Kenta Harada
September 25, 2024
More Decks by Kenta Harada
See All by Kenta Harada
ATOM Matrixで作る BLE MIDIコントローラー
kharada_bt
0
220
M5Stackで作るBLE MIDIコントローラー
kharada_bt
0
890
Androidだって音楽アプリが作りたい(M5Stackによる実演付き)
kharada_bt
0
250
Other Decks in Programming
See All in Programming
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
なぜCTOを降りてFDEを選んだのか?〜なぜプロダクト企業がFDEで顧客の現場に踏み込むのか〜
gonta
1
220
最近”作らせてる” ローカルAIアプリの話
akit37
0
480
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
720
Performance Optimization With LLMs
xleitix
0
150
sbt 2.0: takeoff
eed3si9n
0
160
Web Framework Benchmark Battle 2026, Any%
a_matsuda
2
2.5k
機械に任せるテスト、人が見るテスト ⽣成AIで引き直した、運⽤保守フェーズの線引き
dske104
0
190
Kotlinの15年とServer-Side Kotlin
n_takehata
1
150
When benchmarks go bad - what I learned from measuring performance wrong
hollycummins
0
220
Simple Storage Service(S3) is not simple
iwatsukayura
0
290
re:Inventに行く前に知っておきたい現地参加のノウハウ
nokomoro3
0
440
Featured
See All Featured
A better future with KSS
kneath
240
18k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
PRO
1
1.6k
How STYLIGHT went responsive
nonsquared
100
6.3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
31k
Fireside Chat
paigeccino
43
4.1k
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
450
Discover your Explorer Soul
emna__ayadi
2
1.3k
Done Done
chrislema
187
17k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
RailsConf 2023
tenderlove
30
1.6k
How to build a perfect <img>
jonoalderson
1
6.1k
Producing Creativity
orderedlist
PRO
348
41k
Transcript
元組み込みエンジニアがKotlin のビット演算を使ってみた Kenta Harada 2024/09/24 Kotlin愛好会 vol. 54
Hello!! 元組み込みエンジニア(Symbian OS、家電等) 現在はフリーランスのAndroidエンジニア IoT、モビリティに関するアプリを作っています。 Name : Kenta Harada
contact me at @kharada_bt
チャリチャリ
スマートロック
ビット演算? なるほどわからん 引用元:https://www.javadrive.jp/start/ope/index8.html
1バイトは何ビット? 0 0 0 0 0 0 0 0 8
ビット (0 ~ 255)
Kotlinでビット演算に使う型 符号付き 引用元:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/
Kotlinでビット演算に使う型 符号なし 引用元:https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/
ビット演算を 何に使っているのか? ?
BLE機器との通信
(例)プロトコル 要求 引用元:Bluetooth Core Specification 6.0 0x02 2バイト 0 ~
65535
(例)プロトコル 引用元:Bluetooth Core Specification 6.0 0 0 0 0
0 1 0 0 0 0 0 1 0 1 1 1 0x02 1 2 0x0F
もったいないビット 0 0 0 0 0 1 0 0 0
0 0 1 0 1 1 1 0x02 1 2 0x0F もったいない!
ビットの節約 引用元:Bluetooth Core Specification 6.0 0 0 0 0 0
1 0 0 4ビット分 別のデータ入れちゃお!
データを分解してみる 1 1 0 0 0 1 0 0 0xA2
0 0 0 1 0 1 0 0 0x0A 0 0 0 0 0 1 0 0 0x02
左シフト shl 0 0 0 1 0 1 0 0
1 1 0 0 0 0 0 0 4ビット 左にずらす 0x0A 0xA0
OR演算 or 1 1 0 0 0 0 0 0
0 0 0 0 0 1 0 0 OR 1 1 0 0 0 1 0 0 0xA2 0xA0 0x02
コード
今度は、逆にデータを取り出してみる 0 0 0 0 1 0 1 0 ここのデータを取り出したい
0x14
AND演算 and 1 1 1 0 1 0 1 0
0 0 0 1 1 0 1 0 AND 0 0 0 0 1 0 1 0 0x14 0xF4 0x1C 0 0 0 0 0 0 1 1 0x05 2ビット右にずらす shr
AND演算
Swiftに書き直すと
KotlinとSwiftとCのビット演算子
ご清聴ありがとうございました