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
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Kenta Harada
September 25, 2024
Programming
74
0
Share
元組み込みエンジニアが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
200
M5Stackで作るBLE MIDIコントローラー
kharada_bt
0
860
Androidだって音楽アプリが作りたい(M5Stackによる実演付き)
kharada_bt
0
240
Other Decks in Programming
See All in Programming
Radical Imagining - LIFT 2025-2027 Policy Agenda
lift1998
0
280
Claude Codeをカスタムして自分だけのClaude Codeを作ろう
terisuke
0
120
安いハードウェアでVulkan
fadis
1
960
The Monolith Strikes Back: Why AI Agents ❤️ Rails Monoliths
serradura
0
310
Don't Prompt Harder, Structure Better
kitasuke
0
720
PHP で mp3 プレイヤーを実装しよう
m3m0r7
PRO
0
260
Codex CLIのSubagentsによる並列API実装 / Parallel API Implementation with Codex CLI Subagents
takatty
2
890
10年分の技術的負債、完済へ ― Claude Code主導のAI駆動開発でスポーツブルを丸ごとリプレイスした話
takuya_houshima
0
2.5k
10 Tips of AWS ~Gen AI on AWS~
licux
5
340
セグメントとターゲットを意識するプロポーザルの書き方 〜採択の鍵は、誰に刺すかを見極めるマーケティング戦略にある〜
m3m0r7
PRO
0
500
AI時代のPhpStorm最新事情 #phpcon_odawara
yusuke
0
170
Cache-moi si tu peux : patterns et pièges du cache en production - Devoxx France 2026 - Conférence
slecache
0
180
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
194
17k
Building an army of robots
kneath
306
46k
Deep Space Network (abreviated)
tonyrice
0
110
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.3k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.3k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.2k
Heart Work Chapter 1 - Part 1
lfama
PRO
5
35k
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
130
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
250
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
790
The untapped power of vector embeddings
frankvandijk
2
1.7k
Paper Plane (Part 1)
katiecoart
PRO
0
6.6k
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のビット演算子
ご清聴ありがとうございました