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
ArrayBufferとBinary
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Daiki Ihara
June 06, 2019
Programming
1
640
ArrayBufferとBinary
2019-06-06 @ meguroes #21
Daiki Ihara
June 06, 2019
Tweet
Share
More Decks by Daiki Ihara
See All by Daiki Ihara
tc39_study
sasurau4
1
770
CLIから見るAngular, React, Vue
sasurau4
1
970
Metro Bundler in Web
sasurau4
0
980
reading-mtc2018-web.pdf
sasurau4
1
560
Other Decks in Programming
See All in Programming
メッセージングを利用して時間的結合を分離しよう #phperkaigi
kajitack
3
290
ふつうのRubyist、ちいさなデバイス、大きな一年 / Ordinary Rubyists, Tiny Devices, Big Year
chobishiba
1
500
それはエンジニアリングの糧である:AI開発のためにAIのOSSを開発する現場より / It serves as fuel for engineering: insights from the field of developing open-source AI for AI development.
nrslib
1
470
Rethinking API Platform Filters
vinceamstoutz
0
140
Angular-Apps smarter machen mit Gen AI: Lokal und offlinefähig - Hands-on Workshop!
christianliebel
PRO
0
130
Symfony + NelmioApiDocBundle を使った スキーマ駆動開発 / Schema Driven Development with NelmioApiDocBundle
okashoi
0
210
Goの型安全性で実現する複数プロダクトの権限管理
ishikawa_pro
2
900
Kubernetesでセルフホストが簡単なNewSQLを求めて / Seeking a NewSQL Database That's Simple to Self-Host on Kubernetes
nnaka2992
0
170
Vuetify 3 → 4 何が変わった?差分と移行ポイント10分まとめ
koukimiura
0
170
CS教育のDX AIによる育成の効率化
niftycorp
PRO
0
150
Migration to Signals, Signal Forms, Resource API, and NgRx Signal Store @Angular Days 03/2026 Munich
manfredsteyer
PRO
0
130
Understanding Apache Lucene - More than just full-text search
spinscale
0
140
Featured
See All Featured
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
Paper Plane
katiecoart
PRO
0
48k
Music & Morning Musume
bryan
47
7.1k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Joys of Absence: A Defence of Solitary Play
codingconduct
1
320
Exploring anti-patterns in Rails
aemeredith
2
290
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
So, you think you're a good person
axbom
PRO
2
2k
The Cost Of JavaScript in 2023
addyosmani
55
9.8k
Six Lessons from altMBA
skipperchong
29
4.2k
Git: the NoSQL Database
bkeepers
PRO
432
67k
The Invisible Side of Design
smashingmag
302
51k
Transcript
ArrayBuffer とBinary sasurau4 Meguro.es #21 2019/06/06
Introduce myself { "id": "sasurau4", "name": "Daiki Ihara", "description": "Front-end
engineer at CureApp, Inc.", "techs": { "work": [ "React Native", "TypeScript", "JavaScript", "MongoDB" ], "hobby": ["React", "TypeScript", "JavaScript" ,"deno"], }, "homepage": "https://sasurau4.github.io/profile/" }
Today's contents 4 7 17 1. はじめに 2. バイナリとは 3.
バイナリーで遊ぶ
なぜArrayBuffer 仕事でBluetooth でとある機器をつなぐ必要があった その機器がこんな値を返してくる [48, 49, 48, 46, 48] [48,
48, 49, 46, 50] [48, 48, 48, 46, 56] どうもBinary らしい Binary を扱う?どうするんだ?
ArrayBuffer
None
binary binary: 2 の, 2 進法の, 2 成分の bi-: 2
つの bicycle: 2 つの輪 -> ⾃転⾞ bilingual: 2 つの⾔葉 -> 2 カ国語を喋れる⼈ git bisect: 2 分探索してくれるやつ
binary バイナリ (binary) とは⼆進法のことであるが、コンピュータが処理・記憶するために2 進化されたファイルまたは その内部表現の形式(バイナリデータ)のことを指して⽤いることが多い。 https://ja.wikipedia.org/wiki/%E3%83%90%E3%82%A4%E3%83%8A%E3%83%AA
10
2 進数 0 と1 だけで表現された数値
1 桁のとき 0 1
2 桁のとき 00 01 10 11
3 桁のとき 000 001 010 011 100 101 110 111
例1 10 進数: 255 2 進数: 11111111 例2 10 進数:
10000 2 進数: 10011100010000
16 進数 0-9 とA-F の16 ⽂字を使って表現された数値 JavaScript では、0x00 など0x を先頭につけて表す
10 進数: 255 2 進数: 11111111 16 進数: FF
bit とbyte bit 情報量の単位 binary digit の略 1bit で2 進数の1
桁で表せる情報量、つまり2 つの状態を表せる byte 情報量の単位 1byte = 8bit = 256 通りの値を⽰せる 16 進数で表すのにちょうどよい
ArrayBuffer とTypedArray とDataView バッファ ArrayBuffer 固定⻑のバイナリデータを⽰すために使われる 直接操作ができない ビュー TypedArray ArrayBuffer
の配列状のビューを提供する Uint8Array など DataView 任意のデータをバッファに読み書きする TypedArray と違い、バイトオーダーを制御できる
実践 const buf = new ArrayBuffer(1) let u8 = new
Uint8Array(buf) u8[0] = 65 String.fromCharCode.apply(0, u8) // -> "A" const buf = new ArrayBuffer(2) let u8 = new Uint8Array(buf) let u16 = new Uint16Array(buf) u16[0] = 12354 // u8 -> Uint8Array[66, 48] // u16 -> Uint16Array[12354] String.fromCharCode.apply(0, u8) // -> "B0" String.fromCharCode.apply(0, u16) // -> " あ"
https://developer.mozilla.org/ja/docs/Web/JavaScript/Typed_arrays
最初の疑問の答え const value = [48, 49, 48, 46, 48] value.map(v
=> String.fromCharCode(v)).join("") // -> "010.0"
まとめ バイナリの世界は奥が深い コンピューターの気持ちになれる