title: Convert one-hot encoding to plain binary
body: <p>This isn't a regular "binary to bcd" question, in fact, I'm not really sure what to call the thing I'm trying to do!</p>
  
  <p>There is a single byte in an embedded device that stores the numbers 1 through 7 (for days of the week) in the following format:</p>
  
  <pre><code>00000001 = 1
  00000010 = 2
  00000100 = 3
  00001000 = 4
  00010000 = 5
  00100000 = 6
  01000000 = 7
  </code></pre>
  
  <p>I want to read this byte, and convert its contents (1 through 7) into BCD, but I'm not sure how to do this.</p>
  
  <p>I know I could just brute-force it with a series of if statements:</p>
  
  <pre><code>if(byte == B00000001) 
  {
      answer = 1; 
  }
  else
  if(byte == B00000010) 
  {
      answer = 2; 
  }
  </code></pre>
  
  <p>and so on, but I think there could be a better way. This data is stored in a single register on a real time clock. I'm getting this byte by performing an I2C read, and I read it into a byte in my program. The datasheet for this real-time clock specifies that this particular register is formatted as I have outlined above.</p>