void mmi_i2c_write_cmd(int argc, char *argv[]) { u8 dest_addr; u8 dest_data, length; int i; if(argc == 3) { dest_addr = htoi(argv[1]); dest_data = htoi(argv[2]); BBM_TUNER_WRITE(hDevice, dest_addr, 1, &dest_data, 1); } else if(argc == 4) { dest_addr = htoi(argv[1]); dest_data = htoi(argv[2]); length = htoi(argv[3]); if(dest_data == 0x1234) { dest_data = 0; for(i=0; i<=length; i++) BBM_TUNER_WRITE(hDevice, dest_addr+i, 1, &dest_data, 1); } else { for(i=0; i<length; i++) BBM_TUNER_WRITE(hDevice, dest_addr+i, 1, &dest_data, 1); } } else { print_log("Usage : %s [start addr] [data] [length]\n", argv[0]); } }
void mmi_bbm_i2c_verify(int argc, char *argv[]) { u8 dest_addr; u8 dest_data, temp_data; int retry, delay = 1; int i; switch(argc) { case 3: dest_addr = htoi(argv[1]); retry = htoi(argv[2]); dest_data = 0; for(i=0; i<retry; i++) { dest_data++; BBM_TUNER_WRITE(hDevice, dest_addr, 1, &dest_data, 1); BBM_TUNER_READ(hDevice, dest_addr, 1, &temp_data, 1); if(dest_data != temp_data) { print_log("\n0x%Xth Mismatch Data ; addr[0x%X] write [0x%X] : read [0x%X]\n", i, dest_addr, dest_data, temp_data); } print_log("."); } break; default: print_log("Usage : %s [address] [retry] [delay]\n", argv[0]); break; } }
void mmi_i2c_read_cmd(int argc, char *argv[]) { u8 addr; u8 data[256], length; u8 tmp; int i; if(argc == 2) { data[0] = 0; addr = htoi(argv[1]); BBM_TUNER_READ(hDevice, addr, 1, &data[0], 1); print_log("[0x%08X] : 0x%02X\n", addr, data[0]); } else if(argc == 3) { addr = htoi(argv[1]); length = htoi(argv[2]); for(i=0; i<length; i++) { tmp = addr+i; BBM_TUNER_READ(hDevice, tmp, 1, &data[i], 1); } for(i=0; i<length; i++) { tmp = addr+i; if((i % 8) == 0) print_log("\n[0x%08X] : ", tmp); print_log("%02X ", data[i] & 0xFF); } print_log("\n"); } else { print_log("Usage : %s [start addr] [length]\n", argv[0]); } }
int main(int argc, char* argv[]) { if (argc < 2) { printf("Need at least one parameter.\n"); exit(0); } char* string = argv[1]; int size = sizeof(string)/sizeof(string[0]); if (size < 3) { htoi(string); } else { int first, second, i; first = tolower(string[0]); second = tolower(string[1]); if (first == '0' && second == 'x') { char new_string[size-2]; for(i = 2; i<size; i++) { new_string[i-2] = string[i]; } htoi(new_string); } else { htoi(string); } } }
void mmi_bbm_wread(int argc, char *argv[]) { u16 length; u16 dest_addr, target_addr; u16 data; int i; if(argc == 2) { dest_addr = htoi(argv[1]); BBM_WORD_READ(hDevice, dest_addr, &data); print_log("[0x%04X] : 0x%04X\n", dest_addr, data); } else if(argc == 3) { dest_addr = htoi(argv[1]); length = htoi(argv[2]); for(i=0; i<length; i+=2) { target_addr = dest_addr + i; if((i % 4) == 0) print_log("\n[0x%04X] : ", target_addr); BBM_WORD_READ(hDevice, target_addr, &data); print_log("%04X\n", data); } print_log("\n"); } else { print_log("usage : %s [start addr] [length] ; word read command\n", argv[0]); } }
void mmi_bbm_read(int argc, char *argv[]) { u16 addr; u16 length; u8 data; int i; if(argc == 2) { addr = htoi(argv[1]); BBM_READ(hDevice, addr, &data); print_log("[0x%04X] : 0x%02X\n", addr, data); } else if(argc == 3) { addr = htoi(argv[1]); length = htoi(argv[2]); for(i=0; i<length; i++) { if((i % 8) == 0) print_log("\n[0x%04X] : ", addr+i); BBM_READ(hDevice, addr+i, &data); print_log("%02X ", data & 0xFF); } print_log("\n"); } else { print_log("usage : %s [start addr] [length] ; byte read command\n", (int)argv[0]); } }
int main() { printf("0xFF = %d\n", htoi("0xFF")); printf("0x12 = %d\n", htoi("0x12")); printf("0xA2 = %d\n", htoi("0xA2")); printf("0xA12 = %d\n", htoi("0xA12")); return 0; }
void geticon() { char ch; fgets(inputline,MAXLINE,rcfile); line++; if (strncmp(inputline,"BEGIN",5)) { fprintf(stderr,"Expecting BEGIN at line %d\n",line); exit(3); } if ( (iconfile = fopen(iconname,"wb")) == (FILE *)NULL) { fprintf(stderr,"Can't open ICON file %s\n",iconname); exit(4); } fgets(inputline,MAXLINE,rcfile); line++; while (strncmp(inputline,"END",3) && !feof(rcfile)) { for (p = inputline; *p && (*p==' ' || *p == '\t' || *p=='\''); p++); while (isxdigit(*p)) { ch = htoi(*p++)<<4; ch += htoi(*p++); fputc(ch, iconfile); p++; } fgets(inputline,MAXLINE,rcfile); line++; } fclose(iconfile); }
void mmi_bbm_write(int argc, char *argv[]) { u16 dest_addr; u8 dest_data; u8 length; int i; if(argc == 3) { dest_addr = htoi(argv[1]); dest_data = htoi(argv[2]); BBM_WRITE(hDevice, dest_addr, dest_data); } else if(argc == 4) { dest_addr = htoi(argv[1]); dest_data = htoi(argv[2]); length = htoi(argv[3]); if(dest_data == 0x1234) { dest_data = 0; for(i=0; i<=length; i++) BBM_WRITE(hDevice, dest_addr+i, dest_data); } else { for(i=0; i<length; i++) BBM_WRITE(hDevice, dest_addr+i, dest_data); } } else { print_log("usage : %s [start addr] [data] [length] ; byte write command\n", (int)argv[0]); } }
int main() { printf("%d\n", htoi("9")); printf("%d\n", htoi("f")); printf("%d\n", htoi("A")); return 0; }
int main (void) { printf ("0x1 is %d\n", htoi ("0x1")); // 1 printf ("f is %d\n", htoi ("f")); //15 printf ("ef is %d\n", htoi ("ef")); // 239 printf ("0X5B7c is %d\n", htoi ("0X5B7c")); // 23420 return 0; }
int main(){ char a[50] = "0x5f3z"; char b[50] = "0X5f3"; char c[50] = "5f3w"; printf("%s = %d %d %d \n", a, htoi(a), htoi(b), htoi(c)); return 0; }
void str2hex(A_UINT8 *hex, char *str) { int i; int len = strlen(str); for (i = 2; i < len; i += 2) { hex[(i - 2) / 2] = htoi(str[i]) * 16 + htoi(str[i + 1]); } }
uint8_t hex2int(char c1, char c2) { #define HEX_BIGENDIAN #if defined(HEX_BIGENDIAN) return (htoi(c1) << 4) + htoi(c2); // bigendian #else return (htoi(c2) << 4) + htoi(c1); // littleendian #endif }
main() { printf("0xF: %d\n", htoi("0xF")); printf("0XF: %d\n", htoi("0xF")); printf("0xf: %d\n", htoi("0xF")); printf("f: %d\n", htoi("0xF")); printf("F: %d\n", htoi("0xF")); return 0; }
/* Write the function htoi(s), which converts a string of hexadecimal digits * (including an optional 0x or 0X) into its equivalent integer value. * The allowable digits are 0 through 9, a through f, and A through F. */ int main() { printf("c = %d\n", htoi("c")); printf("1A = %d\n", htoi("1A")); printf("0xfe = %d\n", htoi("0xfe")); printf("0X4B9 = %d\n", htoi("0X4B9")); printf("0zYB9 = %d\n", htoi("0zYB9")); return 0; }
int main(void) { printf("%d\n", htoi("0x80")); printf("%d\n", htoi("x80")); printf("%d\n", htoi("80")); getchar(); return 0; }
int main() { /* Example usage */ printf("%d\n", htoi("AF58")); printf("%d\n", htoi("")); printf("%d\n", htoi("0xAA4")); printf("%d\n", htoi("0XA")); printf("%d\n", htoi("512")); return 0; }
int main(int argc, char const *argv[]) { /* int output; output = htoi(argv[1]); */ char *test1 = "99"; char *test2 = "AC"; char *test3 = "0xAC"; char *test4 = "0XFF"; char *test5 = "0X99"; char *test6 = "123456"; char *test7 = "0x123456"; char *test8 = "F00"; char *test9 = "bar"; printf("Hex:%s; Decimal:%d\n", test1, htoi(test1)); printf("Hex:%s; Decimal:%d\n", test2, htoi(test2)); printf("Hex:%s; Decimal:%d\n", test3, htoi(test3)); printf("Hex:%s; Decimal:%d\n", test4, htoi(test4)); printf("Hex:%s; Decimal:%d\n", test5, htoi(test5)); printf("Hex:%s; Decimal:%d\n", test6, htoi(test6)); printf("Hex:%s; Decimal:%d\n", test7, htoi(test7)); printf("Hex:%s; Decimal:%d\n", test8, htoi(test8)); printf("Hex:%s; Decimal:%d\n", test9, htoi(test9)); return 0; }
int main(void) { printf("FFFF converts to %u\n", htoi("FFFF")); printf("0xFFFF converts to %u\n", htoi("0xFFFF")); printf("ABCD converts to %u\n", htoi("ABCD")); printf("0xFFFFFFFF converts to %u\n", htoi("0xFFFFFFFF")); printf("converting an empty string yields %u\n", htoi("")); return 0; }
int main() { assert(htoi("0xAB") == 171); assert(htoi("0Xabc") == 2748); assert(htoi("abc") == 2748); assert(htoi("FFF") == 4095); assert(htoi("0XA") == 10); assert(htoi("2") == 2); assert(htoi("0x2") == 2); assert(htoi("zog") == -1); assert(htoi("XXA") == -1); assert(htoi("deadbeef") == 3735928559 ); }
unsigned short chtoshort_hex(char s[])//only for 0xaabb { unsigned short a; unsigned char m[2],s1[5]; int i; strncpy(s1,s,4); //printf("s1=%s\n",s1); m[0]=htoi(s1); m[1]=htoi(s+4); //printf("s=%s\n",s+4); a=(m[0]<<8)|m[1]; return a; }
void mmi_bbm_verify(int argc, char *argv[]) { u8 dest_addr; u8 dest_data, temp_data; int i; int retry; switch(argc) { case 2: dest_data = 0xAA; dest_addr = htoi(argv[1]); print_log("%s [0x%X] [0x%X] [0x%X]\n", argv[0], dest_addr, dest_data, 1); BBM_WRITE(hDevice, dest_addr, dest_data); //Sleep(10); BBM_READ(hDevice, dest_addr, &temp_data); if(dest_data != temp_data) { print_log("Mismatch Data ; addr[0x%X] write [0x%X] : read [0x%X]\n", dest_addr, dest_data, temp_data); } break; case 3: dest_data = 0xff; dest_addr = htoi(argv[1]); retry = htoi(argv[2]); print_log("%s [0x%X] [0x%X]\n", argv[0], dest_addr, retry); for(i=0; i<retry; i++) { BBM_WRITE(hDevice, dest_addr, dest_data); //Sleep(10); BBM_READ(hDevice, dest_addr, &temp_data); if(dest_data != temp_data) { print_log("\n 0x%xth Mismatch Data ; addr[0x%X] write [0x%X] : read [0x%X]\n", i, dest_addr, dest_data, temp_data); } dest_data--; print_log("."); } break; default: print_log("Usage : %s [address] [retry]\n", argv[0]); break; } }
void decrypt(char *hash, char *password) { int seed, index, i, c; if (hash != NULL && strlen(hash) > 3 && password != NULL) { seed = htoi(hash[0]) * 10 + htoi(hash[1]); index = 0; for (i = 2; i < (int) strlen(hash); i += 2) { c = htoi(hash[i]) * 16 + htoi(hash[i + 1]); password[index++] = (char) c ^ xlat[(seed++) % XLAT_SIZE]; } } }
int main() { char s[] = "0xFF"; char s2[] = "0xff"; char s3[] = " ff"; char s4[] = " 9"; char s5[] = " 5zlksfj"; printf("%10s is %d\n", s, htoi(s)); printf("%10s is %d\n", s2, htoi(s2)); printf("%10s is %d\n", s3, htoi(s3)); printf("%10s is %d\n", s4, htoi(s4)); printf("%10s is %d\n", s5, htoi(s5)); return 0; }
int main() { /* empty will be treated as zero, which perhaps means false */ assert(0 == htoi("")); assert(0 == htoi("0")); assert(0 == htoi("0x")); assert(0 == htoi("x")); assert(0x123 == htoi("123")); assert(0x1f == htoi("1f")); assert(0xa0 == htoi("0xa0")); assert(0xa0 == htoi("0XA0")); /* wrong input will be truncated */ assert(0xa0 == htoi("a0hell")); assert(0xa0 == htoi("0xa0hell")); return 0; }
int main(int argc, char const *argv[]) { clock_t start, end; double cpu_time_used; start = clock(); htoi("0xf9"); sqrt(100); printf("%f\n", sqrt(21223)); char s[] = "i am a students"; char *s1 = squeeze(s, 's'); printf("%s\n", s1); end = clock(); cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC; printf("elapsed time:%f\n", cpu_time_used); char a1[] = "this is string1\0 "; char a2[] = "this is string2"; strcat(a1, a2); printf("%s\n", a1); return 0; }
int getAsciiFromHEX(const char *strHex, char *strAscii) { unsigned int c=0, i=0, j=0, k=0, strTam=0, asciiLen=0; char strPairHex[3]={0}; strTam=strlen(strHex); for(i=0, j=0; i<strTam; i++) { if(isalpha(strHex[i]) || isdigit(strHex[i])) { strPairHex[j++]=strHex[i]; strPairHex[j]=0;// Poner la terminacion de cadena siempre en el siguiente car para pa porsi. } if(j==2 || i==(strTam-1)) { c=htoi(strPairHex); strAscii[k++]=(char) c; strAscii[k]=0;// Poner la terminacion de cadena siempre en el siguiente car para pa porsi. j=0; asciiLen++; } } return asciiLen; }
main() { char x[100]; while(scanf("%s", x) != 0) printf("%d\n", htoi(x)); }
inline std::string urldecode(const std::string &str_source) { std::string str_dest; for (auto iter = str_source.begin(); iter != str_source.end(); ++iter) { if (*iter == '+') { str_dest.push_back(' '); } else if (*iter == '%' && (str_source.end() - iter) >= 3 && isxdigit(*(iter + 1)) && isxdigit(*(iter + 2))) { str_dest.push_back(htoi(*(iter + 1), *(iter + 2))); iter += 2; } else { str_dest.push_back(*iter); } } return str_dest; }