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
TypeScriptの型で2進数計算
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Riya Amemiya
February 04, 2024
Technology
320
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
TypeScriptの型で2進数計算
Riya Amemiya
February 04, 2024
Transcript
25 slides
TypeScript の型で2 進数計算 西悠太(GMO メディア)
自己紹介 名前: 西悠太 所属: GMO メディア フロントエンドエンジニア X: Riya31377928 https://riya-amemiya-links.oshaburikitchin.com/
なぜ作ったの? とある本でCPUが2進数を計算する仕組み を学んで、あれ?これって型でも実装できる んじゃね?と思って書きました
どんなことができるの?
2進数の計算方法 加算 結果が2なら、1を繰り上げ 減算 1から0を引く場合、左の桁から1を借りる 補数で計算して、オーバーフローは切り捨て
どうやって作る? 2進数の計算方法はわかったけど じゃあどうやれば計算できるの? TypeScriptの型システムに +とか-の演算子はないし.... 論理回路があればできるなら...
どうやって作る? 論理回路を型システムの上に 実装しちゃえばいいんだ! AND OR XOR
None
半加算器を実装する 単純に二数の和のみを求める回路 AND回路とXOR回路が必要 次に作る全加算器の実装に必要
AND回路
XOR回路
半加算器
全加算器を実装する 任意の桁数の2進数の加算、減算ができる 半加算器とOR回路が必要 今回は符号付きで考える
OR回路
材料は揃ったけど... 全加算器には半加算器とOR回路が必要 inferは先頭1文字を取り出す オーバーフローを切り捨てないといけない
N文字取り出す
頭文字を削除
文字列を配列に変換
文字列の長さを取得
文字列を反転
今度こそ材料は揃った! 文字列を反転させる 1. 全加算器に投入 2. 不要な部分を切り捨て 3.
None
完成!
https://zenn.dev/gmomedia/articles/820c58037ef246
None
More Decks by Riya Amemiya
See All by Riya Amemiya
How I Made V8's Array.prototype.flat Up to 20× Faster—and the Journey to a Large-Scale OSS Contribution
riyaamemiya
0
30
マネジメントされる側の仕事は「文句」を言うこと
riyaamemiya
7
6.2k
Temporal 最高!でも改めて「日付」について調べたら人類の負債すぎる件
riyaamemiya
0
280
V8のArray.prototype.flatを最大約20倍速くするまでと、巨大OSSへの大規模コミットの道のり
riyaamemiya
1
1.4k
V8コントリビュート超入門
riyaamemiya
0
240
IsAny はなぜ any だけを見抜けるのか
riyaamemiya
0
110
V8のTorqueを語りたい
riyaamemiya
0
160
知ってた?JavaScriptの"正しさ"を検証するテストが5万以上もあること(Test262)
riyaamemiya
1
420
「え?!それ今ではHTMLだけでできるの!?」驚きの進化を遂げたモダンHTML
riyaamemiya
12
6.3k
Other Decks in Technology
See All in Technology
40以上のマイクロサービスを支えるKubernetes JITアクセス — 160以上の恒久RoleBindingを削減
jumpe1
0
120
現場に渡し、構造で守る AI エージェントを活用したセルフサーブのデータ基盤の運用
legalontechnologies
PRO
0
190
社内アプリ基盤「Quartz」による、 非エンジニアとAIに本番デプロイを 任せても壊れないプラットフォームの設計
staka121
PRO
1
480
Platform Engineering をベースとした Agentic Software Factory の実践
110y
3
1.1k
gradle-best-practices 使ってみた
mikanichinose
0
240
Taking back control of your AI development
inesmontani
PRO
0
320
正しくWeb サイトを守るためのコンテンツセキュリティーポリシー
hinalin
1
900
ブース設計、 お前もプロダクトだったのか / So Booth Design Was a Product All Along
akihiro0038
0
200
OWASP AI Agentic Top10に準拠するクラウドネイティブなガードレールの実践(CNDW 2026)
keitah
1
460
AWS re:Invent 2026 FSI Pre-Event Networking Night
junjikoide
0
410
みん強Lightning! データ基盤ひとりでできるかな
endonanana
0
300
AWS Well-Arhitected Frameworkセキュリティの柱 について
miu_crescent
PRO
2
280
Featured
See All Featured
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
680
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.8k
Making Projects Easy
brettharned
120
6.9k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
590
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.2k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
23k
The Limits of Empathy - UXLibs8
cassininazir
2
810
The Cost Of JavaScript in 2023
addyosmani
56
10k
Designing for humans not robots
tammielis
254
26k
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Are puppies a ranking factor?
jonoalderson
2
4.2k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
340