//Data轉成16進制
-(NSString *)getHexCheckSum:(NSData *)_sourceData
{
//轉 16 進制的 Check Sum 算法
int _checkSum = 0;
int _dataLength = _sourceData.length;
Byte *_bytes = (Byte *)[_sourceData bytes];
for( int i=0; i<_dataLength; i++ )
{
//Force the Byte to Unsigned Byte ( to Scope in 0 ~ 255 ) and Convert to Integer type.
_checkSum += (int)( _bytes[i]&0xff );
//_checkSum += _bytes[i];
}
return [NSString stringWithFormat:@"%x", _checkSum];
}
沒有留言:
張貼留言