Ascii/Hex convert in bash

The reason is because hexdump by default prints out 16-bit integers, not bytes. If your system has them, hd (or hexdump -C) or xxd will provide less surprising outputs – if not, od -t x1 is a POSIX-standard way to get byte-by-byte hex output. You can use od -t x1c to show both the byte … Read more

Check if a string is hexadecimal

(1) Using int() works nicely for this, and Python does all the checking for you 🙂 int(‘00480065006C006C006F00200077006F0072006C00640021’, 16) 6896377547970387516320582441726837832153446723333914657L will work. In case of failure you will receive a ValueError exception. Short example: int(‘af’, 16) 175 int(‘ah’, 16) … ValueError: invalid literal for int() with base 16: ‘ah’ (2) An alternative would be to traverse … Read more

Why use hex?

In both cases you cite, the bit pattern of the number is important, not the actual number. For example, In the first case, j is going to be 1, then 2, 4, 8, 16, 32, 64 and finally 128 as the loop progresses. In binary, that is, 0000:0001, 0000:0010, 0000:0100, 0000:1000, 0001:0000, 0010:0000, 0100:0000 and … Read more

‘scanHexInt32’ was deprecated in iOS 13.0

Update to use UInt64 and scanHexInt64: convenience init(hex: String, alpha: CGFloat = 1.0) { var hexFormatted: String = hex.trimmingCharacters(in: CharacterSet.whitespacesAndNewlines).uppercased() if hexFormatted.hasPrefix(“#”) { hexFormatted = String(hexFormatted.dropFirst()) } assert(hexFormatted.count == 6, “Invalid hex code used.”) var rgbValue: UInt64 = 0 Scanner(string: hexFormatted).scanHexInt64(&rgbValue) self.init(red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0, green: CGFloat((rgbValue & 0x00FF00) >> 8) … Read more

Why use hexadecimal constants?

It is likely for organizational and visual cleanliness. Base 16 has a much simpler relationship to binary than base 10, because in base 16 each digit corresponds to exactly four bits. Notice how in the above, the constants are grouped with many digits in common. If they were represented in decimal, bits in common would … Read more

How can I use 3-digit color codes rather than 6-digit color codes in CSS?

The three-digit codes are a shorthand, and #123 is the same as #112233. In the example you give, you’ve (effectively) swapped #FDFEFF for #FFFFFF, which is close to the original colour, but obviously not exact. It doesn’t “matter” which version you use, as such, but three-digit colour codes mean you have a little less choice … Read more

Decoding T-SQL CAST in C#/VB.NET

I went back to Michael’s post, did some more poking and realized that I did need to do a double conversion, and eventually worked out this little nugget: Convert.ToString(Convert.ToChar(Int32.Parse(EncodedString.Substring(intParseIndex, 2), System.Globalization.NumberStyles.HexNumber))); From there I simply made a loop to go through all the characters 2 by 2 and get them “hexified” and then translated to … Read more

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