hexadecimal floating constant in C

0x0.3p10 is an example of a hexadecimal floating point literal, introduced in C99(1). The p separates the base number from the exponent. The 0x0.3 bit is called the significand part (whole with optional fraction) and the exponent is the power of two by which it is scaled. That particular value is calculated as 0.3 in … Read more

Converting hex color to RGB and vice-versa

In python: def hex_to_rgb(value): “””Return (red, green, blue) for the color given as #rrggbb.””” value = value.lstrip(‘#’) lv = len(value) return tuple(int(value[i:i + lv // 3], 16) for i in range(0, lv, lv // 3)) def rgb_to_hex(red, green, blue): “””Return color as #rrggbb for the given color values.””” return ‘#%02x%02x%02x’ % (red, green, blue) hex_to_rgb(“#ffffff”) … Read more

Converting a hex string to a byte array

This implementation uses the built-in strtol function to handle the actual conversion from text to bytes, but will work for any even-length hex string. std::vector<char> HexToBytes(const std::string& hex) { std::vector<char> bytes; for (unsigned int i = 0; i < hex.length(); i += 2) { std::string byteString = hex.substr(i, 2); char byte = (char) strtol(byteString.c_str(), NULL, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)