Created
March 11, 2015 13:49
-
-
Save scottdweber/d57c31c88fc79745efdd to your computer and use it in GitHub Desktop.
Quick script to convert a percentage for an alpha or color channel into its corresponding hex value.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: ./percentToHex <percentValue> | |
# Examples: | |
# ./percentToHex 97.5 | |
# ./percentToHex 78 | |
num="$1 * .01000 * 255" # note: extra zeros for better precision | |
num=`echo "$num" | bc` | |
num=`echo "$num" | python -c "print(\"{:.0f}\".format(round(float(raw_input()))))"` | |
echo "obase=16; $num" | bc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment