title: Convering Big Endian Formatted Bits to Intended Decimal Value While Ignoring First Bit
body: <p>I am a reading binary file and trying to convert from IBM 4 Byte floating point to double in C++. How exactly would one use the first byte of IBM data to find the ccccccc in the given picture </p>
  
  <p><a href="https://i.stack.imgur.com/J5Ft6.png" rel="nofollow noreferrer">IBM to value conversion chart</a></p>
  
  <p>The code below gives an exponent way larger than what the data should have. I am confused with how the line </p>
  
  <pre><code>exponent = ((IBM4ByteValue[0] &amp; 127) - 64);
  </code></pre>
  
  <p>executes, I do not understand the use of the &amp; operator in this statement. But essentially what the previous author of this code implied is that (IBM4ByteValue[0]) is the ccccccc , so does this mean that the ampersand sets a maximum value that the left side of the operator can equal? Even if this is correct though I'm sure how this line accounts for the fact that there Big Endian bitwise notation in the first byte (I believe it is Big Endian after viewing the picture). Not to mention 1000001 and 0000001 should have the same exponent (-63) however they will not with my current interpretation of the previously mentioned line.</p>
  
  <p>So in short could someone show me how to find the ccccccc (shown in the picture link above) using the first byte --> IBM4ByteValue[0]. Maybe accessing each individual bit? However I do not know the code to do this using my array.</p>
  
  <p>**this code is using the std namespace
  **I believe ret should be mantissa * pow(16, 24+exponent)  however if I'm wrong about the exponent I'm probable wrong about this (I got the IBM Conversion from a previously asked stackoverflow question) **I would have just commented on the old post, but this question was a bit too large, pun intended, for a comment. It is also different in that I am asking how exactly one accesses the bits in an array storing whole bytes.</p>
  
  <p>Code I put together using an IBM conversion from previous question answer</p>
  
  <pre><code>for (long pos = 0; pos &lt; fileLength; pos += BUF_LEN) {
      file.seekg(bytePosition);
      file.read((char *)(&amp;IBM4ByteValue[0]), BUF_LEN);
      bytePosition += 4;
      printf("\n%8ld:  ", pos);
  
      //IBM Conversion
  double ret = 0;
  uint32_t mantissa = 0; 
  uint16_t exponent = 0;
  mantissa = (IBM4ByteValue[3] &lt;&lt; 16) | (IBM4ByteValue[2] &lt;&lt; 8)|IBM4ByteValue[1];
  exponent = ((IBM4ByteValue[0] &amp; 127) - 64);
  ret = mantissa * exp2(-24 + 4 * exponent);
  if (IBM4ByteValue[0] &amp; 128) ret *= -1.;
  
  printf(":%24f", ret);
  printf("\n");
  system("PAUSE");
  </code></pre>
  
  <p>}</p>