你好,歡迎來到IOS教程網

 Ios教程網 >> IOS編程開發 >> IOS開發綜合 >> iOS BCD編碼

iOS BCD編碼

編輯:IOS開發綜合




inline static NSData* encodeBCD(NSString *value){
	
	//NSString *value = @"123456";
	NSMutableData *vdata = [[NSMutableData alloc] init];
	__uint8_t bytes[1] = {6};
	[vdata appendBytes:&bytes length:1];
	
	NSRange range;
	range.location = 0;
	range.length = 1;
	for (int i = 0; i < [value length];) {
		
		range.location = i;
		NSString *temp = [value substringWithRange:range];
		int _intvalue1 = [temp intValue];
		_intvalue1 = _intvalue1 << 4;
		
		range.location = i + 1;
		temp = [value substringWithRange:range];
		int _intvalue2 = [temp intValue];
		int intvalue = _intvalue1 | _intvalue2;
		bytes[0] = intvalue;
		[vdata appendBytes:&bytes length:1];
		
		i += 2;
	}
	
	bytes[0] = 255;
	[vdata appendBytes:&bytes length:1];
	bytes[0] = 255;
	[vdata appendBytes:&bytes length:1];
	bytes[0] = 255;
	[vdata appendBytes:&bytes length:1];
	bytes[0] = 255;
	[vdata appendBytes:&bytes length:1];
	
	return [vdata autorelease];
	
}


  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved