Define a []byte without hex.DecodeString
<p>I'm working with a HID driver, and this driver reads onto a <code>[]byte</code> buffer one of a few different reports. When I use <code>hex.EncodeToString(buffer)</code>, it will return a string looking like either <code>0000</code> or <code>0100</code> or <code>0200</code>, etc. I want to check, using a switch, against the input from the HID device, and so I want to predefine these possibilities, up outside the <code>main()</code>, how should I proceed?</p>

<p>I've tried these possibilities:</p>

<pre class="lang-golang prettyprint-override"><code>var LEFT []byte = []byte('0000')
// or
var LEFT []byte = `0000`
// or 
var LEFT []byte = '0000'
// or
var LEFT []byte = '\x00\x00' // from the %q Printf verb
</code></pre>

<p>The alternative is that I call <code>hex.DecodeString("0000")</code> inside the main() function.</p>

<p><strong>Edit</strong></p>

<p>A note on the solution offered, the <code>EncodeToString</code> hex <code>0000</code> or <code>0100</code> is not <em>four</em> bytes but rather <em>two</em>:</p>

<p><code>"\x01"</code> == <code>"01"</code> == <code>'1'</code></p>

<p>so I can use, in order to get 0100, or 0200, as suggested:</p>

<pre class="lang-golang prettyprint-override"><code>var LEFT []byte{1,0}
// or 
var LEFT []byte("\x01\x00")
</code></pre>