title: how to change integer to 2 bytes
body: <p>I have an algorithm problem I need to solve. But I do not really understand the question after spending a day to grasp it.</p>
  
  <blockquote>
    <p>PROBLEM: For this task, you need to write a small program including a
    pair of functions that can</p>
    
    <p>convert an integer into a special text encoding The Encoding Function</p>
    
    <p>This function needs to accept a signed integer in the 14-bit range
    [-8192..+8191] and return a 4 character string.</p>
    
    <p>The encoding process is as follows:</p>
    
    <p>1.Add 8192 to the raw value, so its range is translated to [0..16383]
    2.Pack that value into two bytes such that the most significant bit of each is cleared</p>
    
    <p>Unencoded intermediate value (as a 16-bit integer):</p>
    
    <p>00HHHHHH HLLLLLLL</p>
    
    <p>Encoded value:</p>
    
    <p>0HHHHHHH 0LLLLLLL</p>
    
    <p>1 of 3</p>
    
    <p>Format the two bytes as a single 4-character hexadecimal string and
    return it. Sample values:</p>
    
    <p>Unencoded (decimal) | Intermediate (decimal) | Intermediate (hex) |
    Encoded (hex)</p>
    
    <p>0 | 8192 | 2000 | 4000</p>
    
    <p>-8192 | 0 | 0000 | 0000</p>
    
    <p>8191 | 16383 | 3fff | 7F7F</p>
    
    <p>2048 | 10240 | 2800 | 5000</p>
    
    <p>-4096 | 4096 | 1000 | 2000</p>
  </blockquote>
  
  <p>The part '2.Pack that value into two bytes such that the most significant bit of each is cleared' is my obstacle now.</p>
  
  <p>what should I do with this instruction?
  Thank you so much in advance.</p>
  
  <p>I tried to convert the number to 16bit by the code below. But I don't know what should do next.</p>
  
  <pre><code>let rawInput = parseInt(document.getElementById("inputValue").value);
  let interDec= Number.parseInt(rawInput) + 8192
  let interHex = interDec.toString(16)
  </code></pre>