Skip to content

Instantly share code, notes, and snippets.

@scottdweber
Created March 11, 2015 13:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scottdweber/d57c31c88fc79745efdd to your computer and use it in GitHub Desktop.
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.
#!/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