#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace Std;
int main ()
{
Char Ch[8];
Char ch2[8]={' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 ', ' 0 '};
Ltoa ("0xba", "strtol", +), ch,2);
Cout<<strlen (CH);
for (int i=8-strlen (CH), j=0;i<8;i++,j++)
{
CH2[I]=CH[J];
}
if (ch2[0]== ' 1 ')
{
cout<< "Minus:" <<endl;
cout<< "-" << (256-strtol ("0xba") <<endl;
}
else{
cout<< "+:" <<endl;
Cout<<strtol ("0xba",' + ') <<endl;
}
return 0;
}
^ (* ̄ (oo)  ̄) ^: Red number portion for const char* type;
The main application functions are: Strtol;ltoa
The first function is to convert the string in the first argument to decimal, to the end of the conversion, to the trailing number 2-36, which refers to the numeric binary represented by the preceding string, rather than converting it to a binary.
Strtol is the conversion of the number of the first parameter into the binary of the third parameter and the array of the second argument. Char *ltoa (long Value,char *string,int radix)
The original code, anti-code, complement, operation is not introduced, here just take the opportunistic way ....
The reason why CH2 is used is because LTOA only assigns the binary from the beginning of the effective bit to CH from zero. If there is 0 in front, it is not assigned.
For example: Long (strtol) converted binary:10101--"Ltoa only gave 10101 to ch[0]=1,ch[1]=0,ch[2]=1,ch[3]=0,ch[4]=1 ....... ch[5]=null. etc...
Gives a hexadecimal number of 0xFF 0x80 (only 2 "bit") to convert it to a signed byte of decimal integer