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
Kenta Harada
September 25, 2024
Programming
91
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
Transcript
24 slides
元組み込みエンジニアが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のビット演算子
ご清聴ありがとうございました
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
AI Augmentation Techniques with Liberty
ivargrimstad
1
520
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.4k
DroidKnights 2026 Android A2UI Jetpack Compose 기반의 안전한 AI UI 렌더링 - 박제창
itsmedreamwalker
1
250
Coding with AI: How to trust the storyteller (AWS Community Day Adria, Ljubljana 2026)
slobodan
0
150
baseline으로 마이그레이션, 리팩토링 안전하게 맡기기
fornewid
1
1k
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
150
AIコーディング時代のKotest ユニットテストから APIレベルの仕様固定化テストへ
ooga04
0
270
선언형 햅틱 라이브러리 진동을 소개합니다
l2hyunwoo
1
320
protojson における文字化けの扱い
kazuki1023
0
440
ローカルLLMの基本と近況 2611 / Local LLM basics and recent situation 2611
kishida
3
580
小さなアプリを作って公開するまで
onozaty
0
200
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
780
Featured
See All Featured
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
2
2.1k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
670
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Winning Ecommerce Organic Search in an AI Era - #searchnstuff2025
aleyda
2
2.2k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
2.3k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3.1k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
4
1.3k
Believing is Seeing
oripsolob
1
280
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
290
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.5k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k