/* Setup lexer state. */ void lj_lex_setup(lua_State *L, LexState *ls) { ls->L = L; ls->fs = NULL; ls->n = 0; ls->p = NULL; ls->vstack = NULL; ls->sizevstack = 0; ls->vtop = 0; ls->bcstack = NULL; ls->sizebcstack = 0; ls->lookahead = TK_eof; /* No look-ahead token. */ ls->linenumber = 1; ls->lastline = 1; lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF); next(ls); /* Read-ahead first char. */ if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb && char2int(ls->p[1]) == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ ls->n -= 2; ls->p += 2; next(ls); } if (ls->current == '#') { /* Skip POSIX #! header line. */ do { next(ls); if (ls->current == END_OF_STREAM) return; } while (!currIsNewline(ls)); inclinenumber(ls); } if (ls->current == LUA_SIGNATURE[0]) { setstrV(L, L->top++, lj_err_str(L, LJ_ERR_XBCLOAD)); lj_err_throw(L, LUA_ERRSYNTAX); } }
bool encodeHexString(uint8_t *data, uint32_t dataLength, const char* key, bool swapEndian) { if (swapEndian) { for (int i = dataLength * 2 - 2; i >= 0; i -= 2) { int c1 = char2int(key[i]); int c2 = char2int(key[i + 1]); if (c1 == -1 || c2 == -1) return false; *data++ = c1 * 16 + c2; } } else { for (int i = 0; i < dataLength * 2; i += 2) { int c1 = char2int(key[i]); int c2 = char2int(key[i + 1]); if (c1 == -1 || c2 == -1) return false; *data++ = c1 * 16 + c2; } } return true; }
/* args: s character string representing hex digits len length of s (it does not need to be null-terminated) intbuf pre-allocated array of integers into which the result will be placed, 3 bytes per int. no checks are made as to the length being sufficient, this is the caller's responsibility, strlen(s)/6 + 1 is enough returns: length of int buf used this function packs an array of characters representing hex digits into an array of ints, 3 bytes per int */ int hexstring2int(char *s, int len, unsigned int *intbuf) { int s_ind = 0, int_ind = 0; int remainder; int i; remainder = len%6; int_ind = 0; intbuf[int_ind] = 0; while (remainder && s_ind < len) { intbuf[int_ind] = char2int(s[s_ind++]) | (intbuf[int_ind] << 4); remainder -=1; len-=1; } if (intbuf[int_ind]) int_ind++; while (len>0) { intbuf[int_ind] = 0; for (i=0; i<6; i++) { intbuf[int_ind] = char2int(s[s_ind++]) | (intbuf[int_ind] << 4); } len -=6; int_ind++; } return(int_ind); }
int str2int(char *str){ //printf("%s\n", str); int tam = strlen(str); //printf("%d\n", tam); int sum = 0; int i; //printf("\n%d\n", tenPow(4)); for(i = tam-1; i > 0; i--){ //printf("%c %d %d\n", str[i], char2int(str[i]), tenPow(tam-1-i));//(tam-1-i) sum += (char2int(str[i]) * tenPow(tam-1-i)); } if(str[i] == '-') sum *= -1; else sum += (char2int(str[i]) * tenPow(tam-1)); //printf(">%d<\n", sum); return sum; }
int sim_blosum(char* seq1, char* seq2) { int len = (strlen(seq1) < strlen(seq2) ? (int)strlen(seq1) : (int)strlen(seq2)); int sim = 0; for (int i=0; i<len; i++) sim = Sum_INT_MIN2(sim,BLOSUM[char2int(seq1[i])][char2int(seq2[i])]); return sim; }
// This function assumes src to be a zero terminated sanitized string with // an even number of [0-9a-f] characters, and target to be sufficiently large void Utils::hex2bin(const uint8_t* src, uint8_t* target) { // https://stackoverflow.com/questions/17261798/ while (*src && src[1]) { *(target++) = char2int(*src) * 16 + char2int(src[1]); src += 2; } }
static void parse_cryptokey(AVFormatContext *avfc, const char *str) { int len = strlen(str) / 2; uint8_t *key = av_mallocz(len); int i; avfc->keylen = len; avfc->key = key; for (i = 0; i < len; i++, str += 2) *key++ = (char2int(str[0]) << 4) | char2int(str[1]); }
int main(void) { char (*a)[1000],(*b)[1000],(*c)[1100]; char sum; int T,i = 0,j = 0; scanf("%d",&T); c = (char (*)[1100])malloc(sizeof(char) * 1100 * T); a = (char (*)[1000])malloc(sizeof(char) * 1000 * T); b = (char (*)[1000])malloc(sizeof(char) * 1000 * T); for(i = 0 ;i < T;i++) { memset(a[i],0,sizeof(a[i])); memset(b[i],0,sizeof(b[i])); memset(c[i],0,sizeof(c[i])); scanf("%s",a[i]); scanf("%s",b[i]); int len_a,len_b; len_a = strlen(a[i]); len_b = strlen(b[i]); int carry = 0; j = 0; while(len_a > j || len_b > j) { if(j < len_a && j < len_b) c[i][j] = char2int(a[i][len_a -1 - j]) + char2int(b[i][len_b -1 - j]) + carry; else if(j < len_b && j >= len_a) c[i][j] = char2int(b[i][len_b -1 - j]) + carry; else if(j < len_a && j >= len_b) c[i][j] = char2int(a[i][len_a -1 - j]) + carry; else break; carry = c[i][j] / 10; c[i][j] = c[i][j] % 10; c[i][j] = int2char(c[i][j]); j++; } if(carry) c[i][j] = int2char(carry); } for(i = 0;i < T ;i++) { printf("Case %d:\n", i+1); printf("%s + %s = ", a[i],b[i]); for(j = strlen(c[i]) - 1;j >= 0;j--) printf("%c", c[i][j]); if(i != T -1) printf("\n"); printf("\n"); } free(a); free(b); free(c); }
std::vector<byte> FromHexStringToByte(std::string input) { std::vector<byte> data; //= new byte[input.Length / 2]; std::string HexByte = ""; for (int i = 0; i < input.length() / 2; i++) { HexByte = input.substr(i * 2, 2); unsigned char temp = char2int(HexByte[0]) * 16 + char2int(HexByte[1]); data.push_back(temp); } return data; }
int* nucchar_to_aaint(char* nuc_seq) { int nuc_length = (int)strlen(nuc_seq); int* int_nuc_seq = char2int(nuc_seq); return nucint_to_aaint(int_nuc_seq,nuc_length); }
Block getWordBlock(std::string word, std::fstream& f, bool createIfReauired = false) { seekRW(f, 0); BlockOffset currentOffset = 0; Block b {readBlockFromFile(f)}; for(auto c : word) { unsigned int i = char2int(c); if (b.offsets[i] == 0 ) { if (!createIfReauired) { b.data=0; return b; } BlockOffset off = f.tellp(); Block newBlock {}; seekRW(f, 0, f.end); BlockOffset newCurrent = b.offsets[i] = writeBlockToFile(newBlock, f); seekRW(f, off); writeBlockToFile(b, f); seekRW(f, newCurrent); currentOffset = newCurrent; b = newBlock; } else { currentOffset = b.offsets[i]; seekRW(f, currentOffset); b = readBlockFromFile(f); } } return b; }
/* Setup lexer state. */ int lj_lex_setup(lua_State *L, LexState *ls) { int header = 0; ls->L = L; ls->fs = NULL; ls->n = 0; ls->p = NULL; ls->vstack = NULL; ls->sizevstack = 0; ls->vtop = 0; ls->bcstack = NULL; ls->sizebcstack = 0; ls->lookahead = TK_eof; /* No look-ahead token. */ ls->linenumber = 1; ls->lastline = 1; lj_str_resizebuf(ls->L, &ls->sb, LJ_MIN_SBUF); next(ls); /* Read-ahead first char. */ if (ls->current == 0xef && ls->n >= 2 && char2int(ls->p[0]) == 0xbb && char2int(ls->p[1]) == 0xbf) { /* Skip UTF-8 BOM (if buffered). */ ls->n -= 2; ls->p += 2; next(ls); header = 1; } if (ls->current == '#') { /* Skip POSIX #! header line. */ do { next(ls); if (ls->current == END_OF_STREAM) return 0; } while (!currIsNewline(ls)); inclinenumber(ls); header = 1; } if (ls->current == LUA_SIGNATURE[0]) { /* Bytecode dump. */ if (header) { /* ** Loading bytecode with an extra header is disabled for security ** reasons. This may circumvent the usual check for bytecode vs. ** Lua code by looking at the first char. Since this is a potential ** security violation no attempt is made to echo the chunkname either. */ setstrV(L, L->top++, lj_err_str(L, LJ_ERR_BCBAD)); lj_err_throw(L, LUA_ERRSYNTAX); } return 1; } return 0; }
int luaZ_fill (ZIO *z) { size_t size; const char *buff = z->reader(NULL, z->data, &size); if (buff == NULL || size == 0) return EOZ; z->n = size - 1; z->p = buff; return char2int(*(z->p++)); }
static int bowser_wifi_get_mac_addr(unsigned char *buf) { unsigned char mac_addr[6]; int hexIdx,charIdx; if (!buf) return -EFAULT; for (charIdx = 0, hexIdx = 0; charIdx < 12; hexIdx++) { mac_addr[hexIdx] = char2int(system_mac_addr[charIdx++]); mac_addr[hexIdx] = mac_addr[hexIdx] << 4; mac_addr[hexIdx] = mac_addr[hexIdx] + char2int(system_mac_addr[charIdx++]); } memcpy(buf, mac_addr, 6); return 0; }
bool sensownyBIK(std::string B) { bool kontrola = true; kontrola &= (B.size() == 10); if(kontrola) { for(int i=0; i < 11; i++) { if(0 <= char2int(B[i]) && char2int(B[i]) <= 9); else kontrola = false; } } return kontrola; }
static int fillbuf(LexState *ls) { size_t sz; const char *buf = ls->rfunc(ls->L, ls->rdata, &sz); if (buf == NULL || sz == 0) return END_OF_STREAM; ls->n = (MSize)sz - 1; ls->p = buf; return char2int(*(ls->p++)); }
unsigned long long pat2int(const char *pat) { unsigned long long val = 0; while (*pat) { val = (val << 4) + char2int(*pat); pat += 1; } return val; }
int luaZ_lookahead (ZIO *z) { if (z->n == 0) { int c = luaZ_fill(z); if (c == EOZ) return c; z->n++; z->p--; } return char2int(*z->p); }
void ChannelH11::InputManagement(){ static double h41[1000][300] = {0}; //load pilot data QFile file2("./pilot/pilot_100_re.txt"); if (!file2.open(QIODevice::ReadOnly | QIODevice::Text)) qDebug() << file2.errorString() <<" NO FILE"; QFile file3("./pilot/pilot_100_im.txt"); if (!file3.open(QIODevice::ReadOnly | QIODevice::Text)) qDebug() << file3.errorString() <<" NO FILE"; char str[100]; for( int i = 0 ; i < 100 ; i++){ file2.readLine(str,100); int crr = char2int(str); pilot[i][0] = crr; //qDebug() << "pilot[ "<<i<<" ][0] is :" << pilot[i][0]; file3.readLine(str,100); crr = char2int(str); pilot[i][1] = crr; //qDebug() << "pilot[ "<<i<<" ][1] is :" << pilot[i][1] << endl; }//for QFile file("h_300_1000_re.txt"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) qDebug() << file.errorString(); int length = 1000; for( int i = 0 ; i < length ; i++ ){ for( int j = 0 ; j < 300 ; j++ ){ file.readLine(str,100); double crr = 0; crr = char2double(str); //qDebug() << "crr is :"<<crr; //h41[i][j] = crr*10; h41[i][j] = 0; } } //qDebug() << "h41[40][299] one is :"<< h41[40][299] ; pdata = &h41[0][0]; pdata2 = pdata; file.close(); }
void ChannelH11::InputManagement2(){ //QFile file("datain.txt"); QFile file("./Pilot_send_data/pilot_1200_re.txt"); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << file.errorString(); qDebug() << "Last sentence is in QPSK Inputmanagement." << endl; } //qDebug() << QObject::tr("file text:") << endl << file.readAll(); //char str[100]; char str[100]; for( int i = 0 ; i < 1200 ; i++ ){ file.readLine(str,100); int crr = 0; crr = char2int(str); qDebug() << "pilot[ "<< i <<"][0] is :"<<crr; pilot[i][0] = crr; } //qDebug() << "last one is :"<< qpsk[9][0] ; file.close(); QFile file2("./Pilot_send_data/pilot_1200_im.txt"); if (!file2.open(QIODevice::ReadOnly | QIODevice::Text)){ qDebug() << file2.errorString(); qDebug() << "Last sentence is in QPSK Inputmanagement." << endl; } //qDebug() << QObject::tr("file text:") << endl << file.readAll(); //char str[100]; for( int i = 0 ; i < 1200 ; i++ ){ file2.readLine(str,100); int crr = 0; crr = char2int(str); qDebug() << "pilot[ "<< i <<"][1] is :"<<crr; pilot[i][1] = crr; } //qDebug() <<"apsk[0][0] is :"<< *(pdata) << endl; file2.close(); }
int luaZ_lookahead (ZIO *z) { if (z->n == 0) { if (luaZ_fill(z) == EOZ) return EOZ; else { z->n++; /* luaZ_fill removed first byte; put back it */ z->p--; } } return char2int(*z->p); }
int luaZ_fill (ZIO *z) { size_t size; lua_State *L = z->L; const char *buff; lua_unlock(L); buff = z->reader(L, z->data, &size); lua_lock(L); if (buff == NULL || size == 0) return EOZ; z->n = size - 1; z->p = buff; return char2int(*(z->p++)); }
static int nchar2int(const char *pChar, int num) { int ret = 0; int cnt = 0; unsigned char cval = 0; for (cnt = 0; cnt <num; cnt++) { cval = char2int((unsigned char *)(pChar+cnt)); ret += cval << ((num-cnt-1)*4); } return ret; }
/** * send a unix signal to a process * * expects parameter 1 to be a signal name, parameter 2 to be a valid process * id. */ int main(int argc, char *argv[]) { // get the executable's name char *progname = basename(argv[0]); if (argc != 3) { fprintf(stderr, "Missing parameters, aborting.\n"); usage(progname); exit(5); } // convert signal name to a signal number int sign = signum(argv[1]); // convert string pid to long pid_t pid = char2int(argv[2]); // validate user input if (sign < 1) { fprintf(stderr, "Invalid signal name %s, %d, aborting.\n", argv[1], sign); usage(progname); exit(1); } // check if the pid is greater than 1 if (pid < 2) { fprintf(stderr, "Invalid pid %d, aborting.\n", pid); usage(progname); exit(2); } // check if pid exists, this might only work on linux if ((kill((pid_t) pid, 0)) == -1) { fprintf(stderr, "Process with pid %d not running, aborting.\n", pid); usage(progname); exit(3); } // send signal to pid, if kill returns -1, the process printf("Sending SIGNAL %d to PID %d\n", sign, pid); int is_active = kill((pid_t) pid, sign); if (is_active != 0) { fprintf(stderr, "Failed to send signal %d to pid %d, aborting.\n", sign, pid); usage(progname); exit(4); } return EXIT_SUCCESS; }
int main(int argc, char** argv){ if(argc != 5){ printf("Error argc!\n"); exit(0); } IplImage* src = cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR); IplImage* rep = cvLoadImage(argv[2], CV_LOAD_IMAGE_COLOR); //IplImage* srcCp = cvCreateImage(cvGetSize(src), src->depth, src->nChannels); //cvCopy(src, srcCp, NULL); //IplImage* repCp = cvCreateImage(cvGetSize(rep), src->depth, src->nChannels); //repCp->imageData= rep->imageData; //cvCopy(repCp, rep, NULL); int repH, repW; int posX, posY; posX = char2int(argv[3]); posY = char2int(argv[4]); repH = rep->height; repW = rep->width; printf("%d %d %d %d\n",posX, posY, repW, repH); CvRect replaceROI = cvRect(posX, posY, repW, repH); cvSetImageROI(src, replaceROI); //cvRectangle(srcCp, cvPoint(posX, posY), cvPoint(posX+repW,posY+repH),cvScalar(0,0,255,1),1,8,0); cvCopy(rep, src, NULL); //show(src); cvResetImageROI(src); if(!cvSaveImage(argv[1], src,0)){ printf("error to save\n"); } cvReleaseImage(&rep); cvReleaseImage(&src); }
int luaZ_fill (ZIO *z) { size_t size; lua_State *L = z->L; const char *buff; if (z->eoz) return EOZ; lua_unlock(L); buff = z->reader(L, z->data, &size); lua_lock(L); if (buff == NULL || size == 0) { z->eoz = 1; /* avoid calling reader function next time */ return EOZ; } z->n = size - 1; z->p = buff; return char2int(*(z->p++)); }
int main() { int re,i,l,f,bin,bout; char in[1000],out[1001]; int len,num[1000]; for(i=0; i<10; i++) { c2i['0'+i]=i; i2c[i]='0'+i; } for(i=0; i<26; i++) { c2i['A'+i]=i+10; c2i['a'+i]=i+36; i2c[i+10]='A'+i; i2c[i+36]='a'+i; } scanf("%d",&re); while(re--) { scanf("%d%d",&bin,&bout); scanf("%s",in); len=strlen(in); for(i=0; i<len; i++) num[i]=char2int(in[i]); l=0; while(1) { f=0; for(i=0; i<len-1; i++) if(num[i]) { f=1; num[i+1]+=(num[i]%bout)*bin; num[i]/=bout; } if(num[i]) f=1; out[l++]=int2char(num[i]%bout); num[i]/=bout; if(f==0) break; } printf("%d %s\n",bin,in); printf("%d ",bout); if(l==1) putchar('0'); /**/ else { l--; while(l--) putchar(out[l]); } printf("\n\n"); } }
int cameraComm::cRead (int query) { unsigned char buf[255]; char answer[50]; int i=0, j=0, imax=0; res = read(fd,buf,1); buf[res]=0; answer[i] = buf[0]; //printf("ans=%d i=%d\n", answer[i],i); if (res!=1) { return 1; } //else //printf("buf(0)=%c \n", buf[0]); //printf("durmiendo...\n"); sleep(1); //printf("wake up!\n"); while (res) { //if ((int)buf[0] != 13) i++; res = read(fd,buf,1); buf[res]=0; answer[i] = buf[0]; /*if (res>0){ printf("buf(0)=%c \n", buf[0]); }*/ } imax=i-2; //printf("1ro: %s \n", answer); if ( query == ITF || query == RTI) { sscanf(answer,"%d:%d:%d",&value[0],&value[1],&value[2]); } else if ( query == NET ) { value[0] = char2int(answer[0]); } return 0; }
bool string2int(uint8 *pBuffer, uint16 length) { int i; int j = 0; for (i=0; i < length; ) { gBuffer_Receive[j] = char2int(pBuffer+i); #if 0 char strTemp[35] = {0}; sprintf(strTemp, "gUint8Buffer[%d]=0x%x\r\n",j,gBuffer_Receive[j]); NPI_WriteTransport((uint8*)strTemp, osal_strlen(strTemp)); halSleep(50); #endif j++; i=i+2; } gNumBytes_Receive = j; return true; }
int compareVersion(char* version1, char* version2) { int m = strlen(version1); int n = strlen(version2); int i = 0, j = 0; int ii, jj; int flag = 0; while(flag == 0){ ii = i; jj = j; if(i < m && j == n + 1){ while(i < m){ ii = i; while(i < m && version1[i] != '.') i++; printf("%d\n",char2int(version1, ii, i - 1)); if(char2int(version1, ii, i - 1) != 0) return 1; i++; } return 0; } else if(i == m + 1 && j < n){ while(j < n){ jj = j; while(j < n && version2[j] != '.') j++; printf("%d\n",char2int(version2, jj, j - 1)); if(char2int(version2, jj, j - 1) != 0) return -1; printf("%d\n",char2int(version2, jj, j - 1)); j++; } return 0; } else if(i == m + 1 && j == n + 1) return 0; while(i < m && version1[i] != '.') i++; while(j < n && version2[j] != '.') j++; int v1 = char2int(version1, ii, i - 1); int v2 = char2int(version2, jj, j - 1); flag = v1 > v2 ? 1 : (v1 < v2 ? -1 : 0); i++; j++; } return flag; }