title: Error with range of NSData
body: <p>I am using the <code>CoreBluetooth</code> framework, where after I have updated a value for a characteristic I get the callback <code>didUpdateValueForCharacteristic</code> from the peripheral. Here, I found a snippet do decode the data within the <code>NSData</code> object returned: </p>
  
  <pre><code>- (void) peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error{
  
      NSUInteger *flags = (NSUInteger*) [[[characteristic value] subdataWithRange:NSMakeRange(0, 1)] bytes];
      NSUInteger length;
      if(*flags &amp; 0x01)
      {
          length = 2;
      }
      else
      {
          length = 1;
      }
      NSUInteger *measurement = (NSUInteger*) [[[characteristic value] subdataWithRange:NSMakeRange(1, length)] bytes];
  
      NSLog(@"Value read from char: %d", *measurement);
  }
  </code></pre>
  
  <p>Here the code throws an exception:</p>
  
  <p><code>*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSConcreteData subdataWithRange:]: range {1, 1} exceeds data length 1'</code></p>
  
  <p>Could someone explain why? The value I am supposed to read should be 1 byte. </p>