title: Unpacking and packing back a struct consisting of single bytes
body: <p>I am getting <code>struct.error: bad char in struct format</code> when packing bytes back in the struct even without making any changes to them.</p>
  
  <p>I am trying to do bitwise operations on each byte in RGBTRIPLE of a 24-bit BMP image. For the sake of simplicity, I am posting the code with just one sample bytes sequence representing a pixel in a Bitmap; I don't make any bitwise operations on it, just try to pack it back.</p>
  
  <pre><code>from struct import *
  from collections import namedtuple
  
  def main():
      RGBTRIPLE = namedtuple('RGBTRIPLE', 'rgbtRed rgbtGreen rgbtBlue')
      rgbt_fmt = '=BBB'
      rgbt_size = calcsize(rgbt_fmt)
  
      rgbt_buffer = b'\x1c\x1e\x1f' 
  
      rgbt = RGBTRIPLE._make(unpack(rgbt_fmt, rgbt_buffer))
  
      rgbtRed = rgbt.rgbtRed
      rgbtGreen = rgbt.rgbtGreen
      rgbtBlue = rgbt.rgbtBlue
  
      rgbt_buffer = pack('rgbt_fmt', rgbtRed, rgbtGreen, rgbtBlue)
  
  if __name__ == "__main__":
      main() 
  </code></pre>
  
  <p>From what I understand, the problem is that when I am unpacking bytes, I am getting ints with size > 1 byte. What is the best way to fix the size of those ints at 1 byte, so I can pack them back using the same <code>=BBB</code> struct format?</p>