static int GetHexBase(const char * &line, unsigned char *store, int count, bool fixedLen, bool asc) { line=skipspace(line); const char *sline=line; unsigned char *sstore=store; int scount=count; while(count) { if(line[0]==0 || line[1]==0 || !isxdigit(line[0]) || !isxdigit(line[1])) break; if(asc) { *store++=line[0]; *store++=line[1]; } else { int d1=HexDigit(line[0]); int d0=HexDigit(line[1]); *store++=(d1<<4) + d0; } line+=2; count--; } if(asc) *store=0; // make sure strings are NULL terminated if((!count || (!fixedLen && count!=scount)) && (!*line || isspace(*line) || *line==';' || *line==']' || *line=='/') ) return scount-count; memset(sstore,0,scount); line=sline; return 0; }
void printByte(unsigned int theByte) { char HexBuffer[3]; HexBuffer[2] = 0; HexBuffer[1] = HexDigit(theByte & 0x000f); theByte = theByte >> 4; HexBuffer[0] = HexDigit(theByte & 0x000f); printString(HexBuffer); }
void printHex(unsigned int Number) { char HexBuffer[5]; HexBuffer[4] = 0; HexBuffer[3] = HexDigit(Number & 0x000f); Number = Number >> 4; HexBuffer[2] = HexDigit(Number & 0x000f); Number = Number >> 4; HexBuffer[1] = HexDigit(Number & 0x000f); Number = Number >> 4; HexBuffer[0] = HexDigit(Number & 0x000f); printString(HexBuffer); }
void LCD_Print_Hex(unsigned int number) { char hexBuffer[5]; hexBuffer[4] = 0; hexBuffer[3] = HexDigit(number & 0x000f); number = number >> 4; hexBuffer[2] = HexDigit(number & 0x000f); number = number >> 4; hexBuffer[1] = HexDigit(number & 0x000f); number = number >> 4; hexBuffer[0] = HexDigit(number & 0x000f); LCD_Print_String(hexBuffer); }
//***************************************************************************** // // Decodes a single %xx escape sequence as an ASCII character. // // \param pcEncoded points to the ``%'' character at the start of a three // character escape sequence which represents a single ASCII character. // \param pcDecoded points to a byte which will be written with the decoded // character assuming the escape sequence is valid. // // This function decodes a single escape sequence of the form ``%xy'' where // x and y represent hexadecimal digits. If each digit is a valid hex digit, // the function writes the decoded character to the pcDecoded buffer and // returns true, else it returns false. // // \return Returns \b true on success or \b false if pcEncoded does not point // to a valid escape sequence. // //***************************************************************************** tBoolean DecodeHexEscape(const char *pcEncoded, char *pcDecoded) { if((pcEncoded[0] != '%') || !IsValidHexDigit(pcEncoded[1]) || !IsValidHexDigit(pcEncoded[2])) { return(false); } else { *pcDecoded = ((HexDigit(pcEncoded[1]) * 16) + HexDigit(pcEncoded[2])); return(true); } }
bool IsHex(const std::string& str) { for(std::string::const_iterator it(str.begin()); it != str.end(); ++it) { if (HexDigit(*it) < 0) return false; } return (str.size() > 0) && (str.size()%2 == 0); }
void ReadHEXPwd(LPBYTE b, LPCSTR src) { for(int n = 0; *src; n++) { if(n >= FTP_PWD_LEN) { fprintf(stderr, "Password code too long!\n"); abort(); } if(*src == ',' || isspace(*src)) { src++; continue; } *b++ = (HexDigit(src[0]) << 4) + HexDigit(src[1]); src += 2; } }
/* * Remove NuLib2's normalization magic (e.g. "%2f" for '/'). * * This always results in the filename staying the same length or getting * smaller, so we can do it in place in the buffer. */ void DenormalizePath(NulibState* pState, char* pathBuf) { const char* srcp; char* dstp; char ch; srcp = pathBuf; dstp = pathBuf; while (*srcp != '\0') { if (*srcp == kForeignIndic) { srcp++; if (*srcp == kForeignIndic) { *dstp++ = kForeignIndic; srcp++; } else if (isxdigit((int)*srcp)) { ch = HexDigit(*srcp) << 4; srcp++; if (isxdigit((int)*srcp)) { /* valid, output char */ ch += HexDigit(*srcp); if (ch != '\0') /* used by Win32 converter */ *dstp++ = ch; srcp++; } else { /* bogus '%' with trailing hex digit found! */ *dstp++ = kForeignIndic; *dstp++ = *(srcp-1); } } else { /* bogus lone '%s' found! */ *dstp++ = kForeignIndic; } } else { *dstp++ = *srcp++; } } *dstp = '\0'; Assert(dstp <= srcp); }
std::vector<unsigned char> ParseHex(const char* psz) { // convert hex dump to vector std::vector<unsigned char> vch; while (true) { while (isspace(*psz)) psz++; signed char c = HexDigit(*psz++); if (c == (signed char)-1) break; unsigned char n = (c << 4); c = HexDigit(*psz++); if (c == (signed char)-1) break; n |= c; vch.push_back(n); } return vch; }
bool IsHexNumber(const std::string& str) { size_t starting_location = 0; if (str.size() > 2 && *str.begin() == '0' && *(str.begin()+1) == 'x') { starting_location = 2; } for (auto c : str.substr(starting_location)) { if (HexDigit(c) < 0) return false; } // Return false for empty string or "0x". return (str.size() > starting_location); }
long CKeyRegistry::SetHexKey(CString sString) { sString.MakeUpper(); long key = 0; for (int i = 0; i < sString.GetLength(); i++) { key |= HexDigit(sString[i]); if (i < 7) key <<= 4; } return key; }
void printHex(unsigned int Number) { // Output the number over the serial port as // as hexadecimal string. char TxString[9]; int Index=8; TxString[Index]=0; // terminate the string Index--; while(Index >=0) { TxString[Index]=HexDigit(Number & 0x0f); Number = Number >> 4; Index--; } eputs(TxString); }
void printInteger(unsigned int Number) { // Output the number over the serial port as // as hexadecimal string. // Transmission is framed with a [ ] pair of brackets. char TxString[11]; int Index=9; TxString[0]='['; TxString[9]=']'; TxString[10]=0;// terminate the string Index--; while(Index >0) { TxString[Index]=HexDigit(Number & 0x0f); Number = Number >> 4; Index--; } printString(TxString); }
// // Parse a quoted string. // bool FParse::QuotedString( const TCHAR* Buffer, FString& Value, int32* OutNumCharsRead ) { if (OutNumCharsRead) { *OutNumCharsRead = 0; } const TCHAR* Start = Buffer; // Require opening quote if (*Buffer++ != TCHAR('"')) { return false; } while (*Buffer && *Buffer != TCHAR('"') && *Buffer != TCHAR('\n') && *Buffer != TCHAR('\r')) { if (*Buffer != TCHAR('\\')) // unescaped character { Value += *Buffer++; } else if (*++Buffer == TCHAR('\\')) // escaped backslash "\\" { Value += TEXT("\\"); ++Buffer; } else if (*Buffer == TCHAR('\"')) // escaped double quote "\"" { Value += TCHAR('"'); ++Buffer; } else if (*Buffer == TCHAR('\'')) // escaped single quote "\'" { Value += TCHAR('\''); ++Buffer; } else if (*Buffer == TCHAR('n')) // escaped newline { Value += TCHAR('\n'); ++Buffer; } else if (*Buffer == TCHAR('r')) // escaped carriage return { Value += TCHAR('\r'); ++Buffer; } else // some other escape sequence, assume it's a hex character value { Value += FString::Printf(TEXT("%c"), (HexDigit(Buffer[0]) * 16) + HexDigit(Buffer[1])); Buffer += 2; } } // Require closing quote if (*Buffer++ != TCHAR('"')) { return false; } if (OutNumCharsRead) { *OutNumCharsRead = (Buffer - Start); } return true; }