{"id":"8R8SDCUVqs","url":"https://pastebin.ca/8R8SDCUVqs","raw_url":"https://raw.anybin.ca/8R8SDCUVqs","visibility":"public","access":"public","created_at":1796321146111,"expires_at":1796925946111,"fetch_limit":null,"fetches_used":0,"reads_remaining":null,"size_bytes":4938,"syntax_hint":null,"title":null,"filename":null,"change_note":null,"cipher":null,"cipher_meta":null,"parent_id":null,"root_id":"8R8SDCUVqs","version":1,"owner_id":null,"recipient_id":null,"body":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n  <meta charset=\"UTF-8\">\n  <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n  <title>16-Bit Base Converter</title>\n  <style>\n    body {\n      font-family: system-ui, -apple-system, sans-serif;\n      background-color: #121212;\n      color: #e0e0e0;\n      display: flex;\n      justify-content: center;\n      align-items: center;\n      height: 100vh;\n      margin: 0;\n    }\n    .container {\n      background: #1e1e1e;\n      padding: 2rem;\n      border-radius: 10px;\n      box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);\n      border: 1px solid #2e2e2e;\n      width: 100%;\n      max-width: 420px;\n    }\n    h2 {\n      margin-top: 0;\n      margin-bottom: 0.25rem;\n      color: #ffffff;\n      text-align: center;\n    }\n    .subtitle {\n      text-align: center;\n      font-size: 0.85rem;\n      color: #888;\n      margin-bottom: 1.5rem;\n    }\n    .input-group {\n      margin-bottom: 1.25rem;\n    }\n    label {\n      display: flex;\n      justify-content: space-between;\n      margin-bottom: 0.4rem;\n      font-weight: 600;\n      font-size: 0.9rem;\n      color: #b0b0b0;\n    }\n    .range-hint {\n      font-weight: 400;\n      font-size: 0.8rem;\n      color: #666;\n    }\n    input {\n      width: 100%;\n      padding: 0.7rem;\n      font-size: 1.05rem;\n      font-family: 'Courier New', Courier, monospace;\n      background-color: #2a2a2a;\n      color: #ffffff;\n      border: 1px solid #3d3d3d;\n      border-radius: 6px;\n      box-sizing: border-box;\n      transition: border-color 0.2s;\n    }\n    input::placeholder {\n      color: #555;\n    }\n    input:focus {\n      outline: none;\n      border-color: #4dabf7;\n    }\n    .error {\n      color: #ff6b6b;\n      font-size: 0.875rem;\n      min-height: 1.2rem;\n      text-align: center;\n      margin-top: 0.5rem;\n    }\n  </style>\n</head>\n<body>\n\n  <div class=\"container\">\n    <h2>16-Bit Base Converter</h2>\n    <div class=\"subtitle\">Unsigned 16-bit integer (0 – 65535)</div>\n\n    <div class=\"input-group\">\n      <label for=\"dec\">Decimal <span class=\"range-hint\">Base 10</span></label>\n      <input type=\"text\" id=\"dec\" placeholder=\"e.g. 65535\">\n    </div>\n\n    <div class=\"input-group\">\n      <label for=\"hex\">Hexadecimal <span class=\"range-hint\">Base 16</span></label>\n      <input type=\"text\" id=\"hex\" placeholder=\"e.g. FFFF\">\n    </div>\n\n    <div class=\"input-group\">\n      <label for=\"bin\">Binary <span class=\"range-hint\">16-bit grouped</span></label>\n      <input type=\"text\" id=\"bin\" placeholder=\"e.g. 1111 1111 1111 1111\">\n    </div>\n\n    <div id=\"error-msg\" class=\"error\"></div>\n  </div>\n\n  <script>\n    const decInput = document.getElementById('dec');\n    const hexInput = document.getElementById('hex');\n    const binInput = document.getElementById('bin');\n    const errorMsg = document.getElementById('error-msg');\n\n    const MAX_16BIT = 65535; // 2^16 - 1\n\n    function formatBinary(num) {\n      // Pad to 16 bits and split into groups of 4\n      return num.toString(2).padStart(16, '0').match(/.{1,4}/g).join(' ');\n    }\n\n    function updateFields(source, value) {\n      errorMsg.textContent = '';\n      // Remove all whitespace so users can type or paste spaced binary\n      const cleanVal = value.trim().replace(/\\s+/g, '');\n\n      if (cleanVal === '') {\n        decInput.value = '';\n        hexInput.value = '';\n        binInput.value = '';\n        return;\n      }\n\n      try {\n        let num;\n\n        if (source === 'dec') {\n          if (!/^\\d+$/.test(cleanVal)) throw new Error('Invalid Decimal');\n          num = parseInt(cleanVal, 10);\n        } \n        else if (source === 'hex') {\n          const hexClean = cleanVal.replace(/^0x/i, '');\n          if (!/^[0-9a-fA-F]+$/.test(hexClean)) throw new Error('Invalid Hexadecimal');\n          num = parseInt(hexClean, 16);\n        } \n        else if (source === 'bin') {\n          const binClean = cleanVal.replace(/^0b/i, '');\n          if (!/^[01]+$/.test(binClean)) throw new Error('Invalid Binary');\n          num = parseInt(binClean, 2);\n        }\n\n        if (isNaN(num) || num < 0 || num > MAX_16BIT) {\n          throw new Error('Value exceeds 16-bit unsigned range (0 – 65535)');\n        }\n\n        // Update the other fields\n        if (source !== 'dec') decInput.value = num.toString(10);\n        if (source !== 'hex') hexInput.value = num.toString(16).toUpperCase().padStart(4, '0');\n        if (source !== 'bin') binInput.value = formatBinary(num);\n\n      } catch (err) {\n        errorMsg.textContent = err.message;\n        if (source !== 'dec') decInput.value = '';\n        if (source !== 'hex') hexInput.value = '';\n        if (source !== 'bin') binInput.value = '';\n      }\n    }\n\n    decInput.addEventListener('input', (e) => updateFields('dec', e.target.value));\n    hexInput.addEventListener('input', (e) => updateFields('hex', e.target.value));\n    binInput.addEventListener('input', (e) => updateFields('bin', e.target.value));\n  </script>\n\n</body>\n</html>\n"}