'2025/05/15'에 해당되는 글 1건

  1. 2025.05.15 AL32UTF8 문자 바이트 계산기 (HTML + JS)
posted by 구로공돌이 2025. 5. 15. 09:49

<!DOCTYPE html>
<html lang="ko">
<head>
  <meta charset="UTF-8">
  <title>AL32UTF8 문자 바이트 계산기</title>
  <style>
    body { font-family: Arial, sans-serif; margin: 40px; }
    textarea { width: 100%; height: 100px; font-size: 16px; }
    .result { margin-top: 20px; font-size: 18px; }
  </style>
</head>
<body>
  <h2>AL32UTF8 문자 바이트 계산기</h2>
  <textarea id="inputText" placeholder="여기에 문자열을 입력하세요..."></textarea>
  <div class="result" id="resultBox">총 문자 수: 0 / 예상 바이트 수: 0</div>

  <script>
    const input = document.getElementById('inputText');
    const resultBox = document.getElementById('resultBox');

    input.addEventListener('input', () => {
      const text = input.value;
      let byteCount = 0;

      for (const char of text) {
        const code = char.codePointAt(0);
        if (code <= 0x7F) {
          byteCount += 1; // ASCII
        } else if (code <= 0x7FF) {
          byteCount += 2; // Latin, 한글 자음/모음 단독 등
        } else if (code <= 0xFFFF) {
          byteCount += 3; // 대부분의 한글, 한자
        } else {
          byteCount += 4; // 이모지, 특수 문자
        }
      }

      const charCount = [...text].length;
      resultBox.innerText = `총 문자 수: ${charCount} / 예상 바이트 수: ${byteCount}`;
    });
  </script>
</body>
</html>