跳到主内容
paste
bin
.ca
type · paste · share
⌘
K
系列
bin 系列
pastebin.ca
中心
Share text and code with expiry and privacy controls.
imagebin.ca
Upload and share images with direct links.
filebin.ca
Drop a file and get a shareable link.
notebin.ca
Write Markdown notes with durable links.
turl.ca
Short, reputation-checked links.
attn.ca
Notifications and alerts for your services.
voicebin.ca
Record and share short voice clips.
dnsbin.ca
Inspect DNS and debug records.
登录
?
账户
更多
▾
文档
← 返回文本
›
编辑 / 分支
无标题文本
#8R8SDCUVqs
public / public
新版本
匿名
已创建 8 hours ago
过期于 7 days
4.8 KB
语法:
text
你的更改会创建一个链接到此文本的新文本 — 原始文本不变。
新版本
你的更改会创建一个链接到此文本的新文本 — 原始文本不变。
标题(可选)
文件名
语法
text
text
bash
c
cpp
css
diff
dockerfile
go
html
ini
java
javascript
json
kotlin
lua
makefile
markdown
nginx
php
python
ruby
rust
shellscript
sql
swift
toml
typescript
xml
yaml
可见性
公开动态
访问
public
过期
7 天
10 分钟
1 小时
1 天
7 天
30 天
90 天
自定义…
自定义过期
变更备注
(可选)
任何人都能在公开动态中找到此文本。选择“未列出”即可仅通过链接分享。
创建新版本
取消
粘贴或输入…
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>16-Bit Base Converter</title> <style> body { font-family: system-ui, -apple-system, sans-serif; background-color: #121212; color: #e0e0e0; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; } .container { background: #1e1e1e; padding: 2rem; border-radius: 10px; box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5); border: 1px solid #2e2e2e; width: 100%; max-width: 420px; } h2 { margin-top: 0; margin-bottom: 0.25rem; color: #ffffff; text-align: center; } .subtitle { text-align: center; font-size: 0.85rem; color: #888; margin-bottom: 1.5rem; } .input-group { margin-bottom: 1.25rem; } label { display: flex; justify-content: space-between; margin-bottom: 0.4rem; font-weight: 600; font-size: 0.9rem; color: #b0b0b0; } .range-hint { font-weight: 400; font-size: 0.8rem; color: #666; } input { width: 100%; padding: 0.7rem; font-size: 1.05rem; font-family: 'Courier New', Courier, monospace; background-color: #2a2a2a; color: #ffffff; border: 1px solid #3d3d3d; border-radius: 6px; box-sizing: border-box; transition: border-color 0.2s; } input::placeholder { color: #555; } input:focus { outline: none; border-color: #4dabf7; } .error { color: #ff6b6b; font-size: 0.875rem; min-height: 1.2rem; text-align: center; margin-top: 0.5rem; } </style> </head> <body> <div class="container"> <h2>16-Bit Base Converter</h2> <div class="subtitle">Unsigned 16-bit integer (0 – 65535)</div> <div class="input-group"> <label for="dec">Decimal <span class="range-hint">Base 10</span></label> <input type="text" id="dec" placeholder="e.g. 65535"> </div> <div class="input-group"> <label for="hex">Hexadecimal <span class="range-hint">Base 16</span></label> <input type="text" id="hex" placeholder="e.g. FFFF"> </div> <div class="input-group"> <label for="bin">Binary <span class="range-hint">16-bit grouped</span></label> <input type="text" id="bin" placeholder="e.g. 1111 1111 1111 1111"> </div> <div id="error-msg" class="error"></div> </div> <script> const decInput = document.getElementById('dec'); const hexInput = document.getElementById('hex'); const binInput = document.getElementById('bin'); const errorMsg = document.getElementById('error-msg'); const MAX_16BIT = 65535; // 2^16 - 1 function formatBinary(num) { // Pad to 16 bits and split into groups of 4 return num.toString(2).padStart(16, '0').match(/.{1,4}/g).join(' '); } function updateFields(source, value) { errorMsg.textContent = ''; // Remove all whitespace so users can type or paste spaced binary const cleanVal = value.trim().replace(/\s+/g, ''); if (cleanVal === '') { decInput.value = ''; hexInput.value = ''; binInput.value = ''; return; } try { let num; if (source === 'dec') { if (!/^\d+$/.test(cleanVal)) throw new Error('Invalid Decimal'); num = parseInt(cleanVal, 10); } else if (source === 'hex') { const hexClean = cleanVal.replace(/^0x/i, ''); if (!/^[0-9a-fA-F]+$/.test(hexClean)) throw new Error('Invalid Hexadecimal'); num = parseInt(hexClean, 16); } else if (source === 'bin') { const binClean = cleanVal.replace(/^0b/i, ''); if (!/^[01]+$/.test(binClean)) throw new Error('Invalid Binary'); num = parseInt(binClean, 2); } if (isNaN(num) || num < 0 || num > MAX_16BIT) { throw new Error('Value exceeds 16-bit unsigned range (0 – 65535)'); } // Update the other fields if (source !== 'dec') decInput.value = num.toString(10); if (source !== 'hex') hexInput.value = num.toString(16).toUpperCase().padStart(4, '0'); if (source !== 'bin') binInput.value = formatBinary(num); } catch (err) { errorMsg.textContent = err.message; if (source !== 'dec') decInput.value = ''; if (source !== 'hex') hexInput.value = ''; if (source !== 'bin') binInput.value = ''; } } decInput.addEventListener('input', (e) => updateFields('dec', e.target.value)); hexInput.addEventListener('input', (e) => updateFields('hex', e.target.value)); binInput.addEventListener('input', (e) => updateFields('bin', e.target.value)); </script> </body> </html>