title: How to set multiple bit values within an integer
body: <p>I am coding a program in vb.net using Visual Studio 2015.  I am trying to figure out how to modify individual bits in a 16 bit integer.  The numeric data-type byte-order is little-Indian and is as follows:</p>
  
  <ul>
  <li>origin (2 bits)</li>
  <li>tagged (1 bit)</li>
  <li>addressable (1 bit)</li>
  <li>protocol (12 bits)</li>
  </ul>
  
  <blockquote>
  <pre><code>Field:  [ origin ] [tagged] [addressable] [protocol]
  Bits:    16 15      14       13            12 11 10 9 8 7 6 5 4 3 2 1
  </code></pre>
  </blockquote>
  
  <p>In the example code below, I am trying to figure out how to set origin, tagged, addressable and protocol in the variable "i" which is a 16 bit integer.</p>
  
  <pre><code>  Dim i As UInt16 = 0
    Dim origin As Byte = 0          ' Message origin indicator
    Dim tagged As Byte = 0          ' Determines usage of the Frame Address target field (0 or 1)
    Dim addressable As Byte = 0     ' Message includes a target address (0 or 1)
    Dim protocol As UInt16 = 1024   ' Protocol number: must be 1024 (decimal)
  </code></pre>
  
  <p>Can anyone provide a vb.net example of how I can update the variable "i" so that it contains the bit values for origin, tagged, addressable and protocol?</p>