iOS 16 binary and string conversions

Source: Internet
Author: User

NSString *dictstring = [Dict jsonfragment];//combination of. just use this. Dictstring==={"content":"SADGFDFG","Phoneno":"","Email":"[email protected]"}===//the 16 binary is converted to a normal string. + (NSString *) stringfromhexstring: (NSString *) hexstring {//          Char*mybuffer = (Char*) malloc ((int) [hexstring length]/2+1); Bzero (Mybuffer, [hexstring length]/2+1);  for(inti =0; i < [hexstring length]-1; i + =2) {unsignedintAnint; NSString* Hexcharstr = [hexstring substringwithrange:nsmakerange (I,2)]; Nsscanner* Scanner =[[[ Nsscanner alloc] initwithstring:hexcharstr] autorelease]; [Scanner Scanhexint:&Anint]; Mybuffer[i/2] = (Char) Anint; } nsstring*unicodestring = [NSString stringwithcstring:mybuffer encoding:4]; NSLog (@"------String =======%@", unicodestring); returnunicodestring; }          //the normal string is converted to 16 binary. + (NSString *) hexstringfromstring: (NSString *)string{NSData*myd = [stringdatausingencoding:nsutf8stringencoding]; Byte*bytes = (Byte *) [MyD bytes]; //the following is a byte conversion to 16 binary. NSString *hexstr=@"";  for(intI=0; I<[myd length];i++) {NSString*NEWHEXSTR = [NSString stringWithFormat:@"%x",bytes[i]&0xFF];///16 binary number         if([Newhexstr length]==1) Hexstr= [NSString stringWithFormat:@"%@0%@", Hexstr,newhexstr]; Elsehexstr= [NSString stringWithFormat:@"%@%@", Hexstr,newhexstr]; }     returnhexstr; }

iOS 16 binary and string conversions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.