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
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
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
本の挿絵に困ったから挿絵メーカーを自作した
yoshimura_datam
1
140
想定外の利用がプロダクトの価値を広げる
lycorptech_jp
PRO
0
150
Is the Website Dying?
miriamschwab
0
300
蓄積をどう解釈すれば基盤整備に踏み出せるか — 10 年目のクラウドサインの場合
bengo4com
1
100
現場に渡し、構造で守る AI エージェントを活用したセルフサーブのデータ基盤の運用
legalontechnologies
PRO
0
190
リリースしたで終わらない。 観測できるフロントエンド開発
yamakenji24
4
2k
「正しいデータ」の定義をAI エージェントとつくるGoogleADKによるデータ品質定義の実践
takaha4k
0
160
Go でトランザクション、どう書いてますか?
knwoop
2
680
AIエージェントの認証がまとめて進化! ~pre:Inventで来た3つのアップデート~
minorun365
PRO
2
300
Kubernetes, Agones, WebRTC, GPU で作る クラウドゲーミング基盤を本番運用に乗せるまで
vivion
1
320
対話 AI プラットフォーム「アイブリー」で実践する自然言語処理と事業開発
ivry_presentationmaterials
0
250
統制されたID・権限をどう利用するか : DPoP/FAPIによるAPIセキュリティ強化
oidfj
2
380
Featured
See All Featured
StorybookのUI Testing Handbookを読んだ
zakiyama
31
7.1k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
33
5.9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
How Fast Is Fast Enough? [PerfNow 2025]
tammyeverts
3
1k
The Straight Up "How To Draw Better" Workshop
denniskardys
239
140k
Build your cross-platform service in a week with App Engine
jlugia
234
19k
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Designing for Performance
lara
612
70k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
AI Search: Where Are We & What Can We Do About It?
aleyda
0
8.3k
sira's awesome portfolio website redesign presentation
elsirapls
0
530
Exploring anti-patterns in Rails
aemeredith
4
590