Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
元組み込みエンジニアがKotlinのビット演算を使ってみた
Search
Kenta Harada
September 25, 2024
Programming
0
52
元組み込みエンジニアがKotlinのビット演算を使ってみた
「集まれKotlin好き!Kotlin愛好会 vol. 54@株式会社TOKIUM」で発表した資料です。
Kenta Harada
September 25, 2024
Tweet
Share
More Decks by Kenta Harada
See All by Kenta Harada
ATOM Matrixで作る BLE MIDIコントローラー
kharada_bt
0
170
M5Stackで作るBLE MIDIコントローラー
kharada_bt
0
780
Androidだって音楽アプリが作りたい(M5Stackによる実演付き)
kharada_bt
0
240
Other Decks in Programming
See All in Programming
How mixi2 Uses TiDB for SNS Scalability and Performance
kanmo
36
14k
CNCF Project の作者が考えている OSS の運営
utam0k
6
710
ファインディの テックブログ爆誕までの軌跡
starfish719
2
1.1k
JavaScriptツール群「UnJS」を5分で一気に駆け巡る!
k1tikurisu
9
1.8k
Pulsar2 を雰囲気で使ってみよう
anoken
0
230
自分ひとりから始められる生産性向上の取り組み #でぃーぷらすオオサカ
irof
8
2.7k
Introduction to kotlinx.rpc
arawn
0
680
CI改善もDatadogとともに
taumu
0
110
チームリードになって変わったこと
isaka1022
0
200
Bedrock Agentsレスポンス解析によるAgentのOps
licux
3
830
社内フレームワークとその依存性解決 / in-house framework and its dependency management
vvakame
1
550
Immutable ActiveRecord
megane42
0
140
Featured
See All Featured
A Philosophy of Restraint
colly
203
16k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
Scaling GitHub
holman
459
140k
GitHub's CSS Performance
jonrohan
1030
460k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
193
16k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
160
15k
How STYLIGHT went responsive
nonsquared
98
5.4k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
27
1.5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Code Reviewing Like a Champion
maltzj
521
39k
How to train your dragon (web standard)
notwaldorf
91
5.8k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
21
2.5k
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のビット演算子
ご清聴ありがとうございました