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
59
元組み込みエンジニアが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
180
M5Stackで作るBLE MIDIコントローラー
kharada_bt
0
810
Androidだって音楽アプリが作りたい(M5Stackによる実演付き)
kharada_bt
0
240
Other Decks in Programming
See All in Programming
Quand Symfony, ApiPlatform, OpenAI et LangChain s'allient pour exploiter vos PDF : de la théorie à la production…
ahmedbhs123
0
130
Result型で“失敗”を型にするPHPコードの書き方
kajitack
5
580
AIエージェントはこう育てる - GitHub Copilot Agentとチームの共進化サイクル
koboriakira
0
490
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
120
Porting a visionOS App to Android XR
akkeylab
0
240
20250628_非エンジニアがバイブコーディングしてみた
ponponmikankan
0
650
5つのアンチパターンから学ぶLT設計
narihara
1
150
0626 Findy Product Manager LT Night_高田スライド_speaker deck用
mana_takada
0
140
PHP 8.4の新機能「プロパティフック」から学ぶオブジェクト指向設計とリスコフの置換原則
kentaroutakeda
2
740
Is Xcode slowly dying out in 2025?
uetyo
1
250
Team operations that are not burdened by SRE
kazatohiei
1
300
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
21
3.9k
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
How to train your dragon (web standard)
notwaldorf
94
6.1k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.7k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
53k
Making the Leap to Tech Lead
cromwellryan
134
9.4k
How To Stay Up To Date on Web Technology
chriscoyier
790
250k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
29
1.8k
Rebuilding a faster, lazier Slack
samanthasiow
82
9.1k
Designing Experiences People Love
moore
142
24k
[RailsConf 2023] Rails as a piece of cake
palkan
55
5.6k
The Straight Up "How To Draw Better" Workshop
denniskardys
234
140k
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のビット演算子
ご清聴ありがとうございました