Posts

Showing posts with the label Hex

Converting Hex To Base64 With Notepad++

Answer : The trick was that by converting the HEX directly in notepad++, It's taken as a ASCII value not as A HEX Value as intended. So we need to converted first the HEX --> ASCII then ASCII --> BASE64 1/ Select the string 2/ Using Notepad++ menu: Plugins -> Converter -> HEX -> ASCII 3/ Plugins -> MIME Tools -> Base64 Encode and we get the needed value The characters FB can be encoded as the 16-bit values 46004200 and encoding that in Base 64 gives RkI= . Using Notepad++ menu => TextFx => TextFx Tools => Base 64 decode : Converting +w== gives the single byte xFB . It show as thouse three characters in white on a black background. The status bar at the bottom of the window shows the buffer has a length of 1 (i.e. one). Converting RkI= gives the two characters FB . Shown in black on a white background, i.e. as normal text. The buffer is shown to have a length of 2. Conclusion, your initial conversion was of the two charactgers FB not the byt...

Converting Hex To Decimal In Awk Or Sed

Answer : Here's a variation on Jonathan's answer: awk $([[ $(awk --version) = GNU* ]] && echo --non-decimal-data) -F, ' BEGIN {OFS = FS} { $6 = sprintf("%d", "0x" substr($4, 11, 4)) $5 = sprintf("%d", "0x" substr($4, 7, 4)) $4 = substr($4, 1, 6) print }' I included a rather contorted way of adding the --non-decimal-data option if it's needed. Edit Just for the heck of it, here's the pure-Bash equivalent: saveIFS=$IFS IFS=, while read -r -a line do printf '%s,%s,%d,%d\n' "${line[*]:0:3}" "${line[3]:0:6}" "0x${line[3]:6:4}" "0x${line[3]:10:4}" done IFS=$saveIFS The "${line[*]:0:3}" (quoted * ) works similarly to AWK's OFS in that it causes Bash's IFS (here a comma) to be inserted between array elements on output. We can take further advantage of that feature by inserting array elements as follows ...

Converting Hexadecimal To Float In JavaScript

Answer : Another possibility is to parse the digits separately, splitting the string up in two and treating both parts as ints during the conversion and then add them back together. function parseFloat(str, radix) { var parts = str.split("."); if ( parts.length > 1 ) { return parseInt(parts[0], radix) + parseInt(parts[1], radix) / Math.pow(radix, parts[1].length); } return parseInt(parts[0], radix); } var myno = 28.4382; var convno = myno.toString(16); var f = parseFloat(convno, 16); console.log(myno + " -> " + convno + " -> " + f); Try this. The string may be raw data (simple text) with four characters (0 - 255) or a hex string "0xFFFFFFFF" four bytes in length. jsfiddle.net var str = '0x3F160008'; function parseFloat(str) { var float = 0, sign, order, mantissa, exp, int = 0, multi = 1; if (/^0x/.exec(str)) { int = parseInt(str, 16); } else { for (var i = str.len...

Conversion Hex String Into Ascii In Bash Command Line

Answer : This worked for me. $ echo 54657374696e672031203220330 | xxd -r -p Testing 1 2 3$ -r tells it to convert hex to ascii as opposed to its normal mode of doing the opposite -p tells it to use a plain format. This code will convert the text 0xA7.0x9B.0x46.0x8D.0x1E.0x52.0xA7.0x9B.0x7B.0x31.0xD2 into a stream of 11 bytes with equivalent values. These bytes will be written to standard out. TESTDATA=$(echo '0xA7.0x9B.0x46.0x8D.0x1E.0x52.0xA7.0x9B.0x7B.0x31.0xD2' | tr '.' ' ') for c in $TESTDATA; do echo $c | xxd -r done As others have pointed out, this will not result in a printable ASCII string for the simple reason that the specified bytes are not ASCII. You need post more information about how you obtained this string for us to help you with that. How it works: xxd -r translates hexadecimal data to binary (like a reverse hexdump). xxd requires that each line start off with the index number of the first character on the line (run hexdump on som...

Convert Hex Color To RGB Values In PHP

Answer : If you want to convert hex to rgb you can use sscanf: <?php $hex = "#ff9900"; list($r, $g, $b) = sscanf($hex, "#%02x%02x%02x"); echo "$hex -> $r $g $b"; ?> Output: #ff9900 -> 255 153 0 Check out PHP's hexdec() and dechex() functions: http://php.net/manual/en/function.hexdec.php Example: $value = hexdec('ff'); // $value = 255 I made a function which also returns alpha if alpha is provided as a second parameter the code is below. The function function hexToRgb($hex, $alpha = false) { $hex = str_replace('#', '', $hex); $length = strlen($hex); $rgb['r'] = hexdec($length == 6 ? substr($hex, 0, 2) : ($length == 3 ? str_repeat(substr($hex, 0, 1), 2) : 0)); $rgb['g'] = hexdec($length == 6 ? substr($hex, 2, 2) : ($length == 3 ? str_repeat(substr($hex, 1, 1), 2) : 0)); $rgb['b'] = hexdec($length == 6 ? substr($hex, 4, 2) : ($length == 3 ? str_repeat(substr($hex, 2, 1)...

Convert RGBA To HEX

Answer : Since alpha value both attenuates the background color and the color value, something like this could do the trick: function rgba2rgb(RGB_background, RGBA_color) { var alpha = RGBA_color.a; return new Color( (1 - alpha) * RGB_background.r + alpha * RGBA_color.r, (1 - alpha) * RGB_background.g + alpha * RGBA_color.g, (1 - alpha) * RGB_background.b + alpha * RGBA_color.b ); } (Try it interactively: https://marcodiiga.github.io/rgba-to-rgb-conversion)