//
//? ViewController.m
//? qwe
//
//? Created by 余浩 on 17/5/25.
//? Copyright ? 2017年 余浩. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
NSString *string = [NSString stringWithFormat:@"2565"];
NSData *testData = [string dataUsingEncoding: NSUTF8StringEncoding];
Byte *testByte = (Byte *)[testData bytes];
NSLog(@"data=====%@",testData);
Byte *newByte = (Byte *)malloc([testData length]);
for (int i=0; i<[testData length]; i++) {
newByte[i] = testByte[i]^1;
printf("Byte------------%hhu\n",testByte[i]);//%hhu? 指定signed char 或 unsigned char? ? char是1個(gè)字節(jié)
//? printf("new------------%hhu\n",newByte[i]);
int c = testByte[i] &0xff;? //int類(lèi)型32
NSLog(@"int c==========%d",c);
};
Byte *nByte = (Byte *)malloc(1);
nByte [0] = -127;
NSLog(@"nBytex==========%x",nByte[0]);
int d = nByte[0] &0xff;//0xff在c語(yǔ)言表示一個(gè)十六進(jìn)制無(wú)符號(hào)整數(shù),有符號(hào)轉(zhuǎn)成無(wú)符號(hào)
NSLog(@"d==========%d",d);
NSData *data = [NSData dataWithBytes:newByte length:[testData length]];
NSString *stingaa = [[NSString alloc]initWithData:data encoding:(NSUTF8StringEncoding)];
//反轉(zhuǎn)
NSData *testData1 = [stingaa dataUsingEncoding: NSUTF8StringEncoding];
Byte *testByte1 = (Byte *)[testData1 bytes];
Byte *newByte1 = (Byte *)malloc([testData1 length]);
for (int i=0; i<[testData1 length]; i++) {
newByte1[i] = testByte1[i]^1;
//? printf("newByte1------------%d\n",newByte1[i]);
};
Byte key[1] = {0x32};
NSData *data1 = [NSData dataWithBytes:newByte1 length:[testData length]];
NSString *stingaa1 = [[NSString alloc]initWithData:data1 encoding:(NSUTF8StringEncoding)];
NSLog(@"stingaa1=========%@",stingaa1);
//&(按位與)、|(按位或)、^(按位異或)、~ (按位取反)。
//1個(gè)字節(jié)是8位,二進(jìn)制8位:xxxxxxxx 范圍從
/**
00000000-11111111,表示0到255。
一位16進(jìn)制數(shù)(用二進(jìn)制表示是xxxx)最多只表示到15(即對(duì)應(yīng)16進(jìn)制的F),要表示到255,就還需要第二位。
所以1個(gè)字節(jié)=2個(gè)16進(jìn)制字符,一個(gè)16進(jìn)制位=0.5個(gè)字節(jié)
*/
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end