Skip to content

Instantly share code, notes, and snippets.

@adumont
Created August 26, 2019 22: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 adumont/f6487dfc04d6e727898dc500ac63305f to your computer and use it in GitHub Desktop.
Save adumont/f6487dfc04d6e727898dc500ac63305f to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Magnusson naming for Hexadecimal\n",
"\n",
"This simple function expresses an hexadecimal number between 0 and 255 using it's [Magnusson naming](https://en.wikipedia.org/wiki/Hexadecimal#Verbal_and_digital_representations)."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"def magnusson(n):\n",
" fix=[\"thir\", \"four\", \"fif\", \"six\", \"seven\", \"eight\", \"nine\", \"ann\", \"bet\", \"chris\", \"dot\", \"ernes\", \"fros\"]\n",
" ones = [\"\", \"one \",\"two \",\"three \",\"four \", \"five \", \"six \",\"seven \",\"eight \",\"nine \",\n",
" \"ann \",\"bet \",\"chris \", \"dot\", \"ernest\", \"frost\", \"ten\", \"eleven\", \"twelve\" ] + [ i+\"teen \" for i in fix]\n",
"\n",
" twenties = [\"\",\"\",\"twenty \"] + [ i+\"ty \" for i in fix]; twenties[4]=\"forty\" \n",
" \n",
" c = n % 16\n",
" b = ((n % 256) - c) // 16\n",
" if n == 0:\n",
" return \"zero\"\n",
" elif b <= 1:\n",
" return ones[n%256]\n",
" elif b > 1:\n",
" return twenties[b] + ones[c]\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0 0x0 zero\n",
"1 0x1 one \n",
"2 0x2 two \n",
"3 0x3 three \n",
"4 0x4 four \n",
"5 0x5 five \n",
"6 0x6 six \n",
"7 0x7 seven \n",
"8 0x8 eight \n",
"9 0x9 nine \n",
"10 0xa ann \n",
"11 0xb bet \n",
"12 0xc chris \n",
"13 0xd dot\n",
"14 0xe ernest\n",
"15 0xf frost\n",
"16 0x10 ten\n",
"17 0x11 eleven\n",
"18 0x12 twelve\n",
"19 0x13 thirteen \n",
"20 0x14 fourteen \n",
"21 0x15 fifteen \n",
"22 0x16 sixteen \n",
"23 0x17 seventeen \n",
"24 0x18 eightteen \n",
"25 0x19 nineteen \n",
"26 0x1a annteen \n",
"27 0x1b betteen \n",
"28 0x1c christeen \n",
"29 0x1d dotteen \n",
"30 0x1e ernesteen \n",
"31 0x1f frosteen \n",
"32 0x20 twenty \n",
"33 0x21 twenty one \n",
"34 0x22 twenty two \n",
"35 0x23 twenty three \n",
"36 0x24 twenty four \n",
"37 0x25 twenty five \n",
"38 0x26 twenty six \n",
"39 0x27 twenty seven \n",
"40 0x28 twenty eight \n",
"41 0x29 twenty nine \n",
"42 0x2a twenty ann \n",
"43 0x2b twenty bet \n",
"44 0x2c twenty chris \n",
"45 0x2d twenty dot\n",
"46 0x2e twenty ernest\n",
"47 0x2f twenty frost\n",
"48 0x30 thirty \n",
"49 0x31 thirty one \n",
"50 0x32 thirty two \n",
"51 0x33 thirty three \n",
"52 0x34 thirty four \n",
"53 0x35 thirty five \n",
"54 0x36 thirty six \n",
"55 0x37 thirty seven \n",
"56 0x38 thirty eight \n",
"57 0x39 thirty nine \n",
"58 0x3a thirty ann \n",
"59 0x3b thirty bet \n",
"60 0x3c thirty chris \n",
"61 0x3d thirty dot\n",
"62 0x3e thirty ernest\n",
"63 0x3f thirty frost\n",
"64 0x40 forty\n",
"65 0x41 fortyone \n",
"66 0x42 fortytwo \n",
"67 0x43 fortythree \n",
"68 0x44 fortyfour \n",
"69 0x45 fortyfive \n",
"70 0x46 fortysix \n",
"71 0x47 fortyseven \n",
"72 0x48 fortyeight \n",
"73 0x49 fortynine \n",
"74 0x4a fortyann \n",
"75 0x4b fortybet \n",
"76 0x4c fortychris \n",
"77 0x4d fortydot\n",
"78 0x4e fortyernest\n",
"79 0x4f fortyfrost\n",
"80 0x50 fifty \n",
"81 0x51 fifty one \n",
"82 0x52 fifty two \n",
"83 0x53 fifty three \n",
"84 0x54 fifty four \n",
"85 0x55 fifty five \n",
"86 0x56 fifty six \n",
"87 0x57 fifty seven \n",
"88 0x58 fifty eight \n",
"89 0x59 fifty nine \n",
"90 0x5a fifty ann \n",
"91 0x5b fifty bet \n",
"92 0x5c fifty chris \n",
"93 0x5d fifty dot\n",
"94 0x5e fifty ernest\n",
"95 0x5f fifty frost\n",
"96 0x60 sixty \n",
"97 0x61 sixty one \n",
"98 0x62 sixty two \n",
"99 0x63 sixty three \n",
"100 0x64 sixty four \n",
"101 0x65 sixty five \n",
"102 0x66 sixty six \n",
"103 0x67 sixty seven \n",
"104 0x68 sixty eight \n",
"105 0x69 sixty nine \n",
"106 0x6a sixty ann \n",
"107 0x6b sixty bet \n",
"108 0x6c sixty chris \n",
"109 0x6d sixty dot\n",
"110 0x6e sixty ernest\n",
"111 0x6f sixty frost\n",
"112 0x70 seventy \n",
"113 0x71 seventy one \n",
"114 0x72 seventy two \n",
"115 0x73 seventy three \n",
"116 0x74 seventy four \n",
"117 0x75 seventy five \n",
"118 0x76 seventy six \n",
"119 0x77 seventy seven \n",
"120 0x78 seventy eight \n",
"121 0x79 seventy nine \n",
"122 0x7a seventy ann \n",
"123 0x7b seventy bet \n",
"124 0x7c seventy chris \n",
"125 0x7d seventy dot\n",
"126 0x7e seventy ernest\n",
"127 0x7f seventy frost\n",
"128 0x80 eightty \n",
"129 0x81 eightty one \n",
"130 0x82 eightty two \n",
"131 0x83 eightty three \n",
"132 0x84 eightty four \n",
"133 0x85 eightty five \n",
"134 0x86 eightty six \n",
"135 0x87 eightty seven \n",
"136 0x88 eightty eight \n",
"137 0x89 eightty nine \n",
"138 0x8a eightty ann \n",
"139 0x8b eightty bet \n",
"140 0x8c eightty chris \n",
"141 0x8d eightty dot\n",
"142 0x8e eightty ernest\n",
"143 0x8f eightty frost\n",
"144 0x90 ninety \n",
"145 0x91 ninety one \n",
"146 0x92 ninety two \n",
"147 0x93 ninety three \n",
"148 0x94 ninety four \n",
"149 0x95 ninety five \n",
"150 0x96 ninety six \n",
"151 0x97 ninety seven \n",
"152 0x98 ninety eight \n",
"153 0x99 ninety nine \n",
"154 0x9a ninety ann \n",
"155 0x9b ninety bet \n",
"156 0x9c ninety chris \n",
"157 0x9d ninety dot\n",
"158 0x9e ninety ernest\n",
"159 0x9f ninety frost\n",
"160 0xa0 annty \n",
"161 0xa1 annty one \n",
"162 0xa2 annty two \n",
"163 0xa3 annty three \n",
"164 0xa4 annty four \n",
"165 0xa5 annty five \n",
"166 0xa6 annty six \n",
"167 0xa7 annty seven \n",
"168 0xa8 annty eight \n",
"169 0xa9 annty nine \n",
"170 0xaa annty ann \n",
"171 0xab annty bet \n",
"172 0xac annty chris \n",
"173 0xad annty dot\n",
"174 0xae annty ernest\n",
"175 0xaf annty frost\n",
"176 0xb0 betty \n",
"177 0xb1 betty one \n",
"178 0xb2 betty two \n",
"179 0xb3 betty three \n",
"180 0xb4 betty four \n",
"181 0xb5 betty five \n",
"182 0xb6 betty six \n",
"183 0xb7 betty seven \n",
"184 0xb8 betty eight \n",
"185 0xb9 betty nine \n",
"186 0xba betty ann \n",
"187 0xbb betty bet \n",
"188 0xbc betty chris \n",
"189 0xbd betty dot\n",
"190 0xbe betty ernest\n",
"191 0xbf betty frost\n",
"192 0xc0 christy \n",
"193 0xc1 christy one \n",
"194 0xc2 christy two \n",
"195 0xc3 christy three \n",
"196 0xc4 christy four \n",
"197 0xc5 christy five \n",
"198 0xc6 christy six \n",
"199 0xc7 christy seven \n",
"200 0xc8 christy eight \n",
"201 0xc9 christy nine \n",
"202 0xca christy ann \n",
"203 0xcb christy bet \n",
"204 0xcc christy chris \n",
"205 0xcd christy dot\n",
"206 0xce christy ernest\n",
"207 0xcf christy frost\n",
"208 0xd0 dotty \n",
"209 0xd1 dotty one \n",
"210 0xd2 dotty two \n",
"211 0xd3 dotty three \n",
"212 0xd4 dotty four \n",
"213 0xd5 dotty five \n",
"214 0xd6 dotty six \n",
"215 0xd7 dotty seven \n",
"216 0xd8 dotty eight \n",
"217 0xd9 dotty nine \n",
"218 0xda dotty ann \n",
"219 0xdb dotty bet \n",
"220 0xdc dotty chris \n",
"221 0xdd dotty dot\n",
"222 0xde dotty ernest\n",
"223 0xdf dotty frost\n",
"224 0xe0 ernesty \n",
"225 0xe1 ernesty one \n",
"226 0xe2 ernesty two \n",
"227 0xe3 ernesty three \n",
"228 0xe4 ernesty four \n",
"229 0xe5 ernesty five \n",
"230 0xe6 ernesty six \n",
"231 0xe7 ernesty seven \n",
"232 0xe8 ernesty eight \n",
"233 0xe9 ernesty nine \n",
"234 0xea ernesty ann \n",
"235 0xeb ernesty bet \n",
"236 0xec ernesty chris \n",
"237 0xed ernesty dot\n",
"238 0xee ernesty ernest\n",
"239 0xef ernesty frost\n",
"240 0xf0 frosty \n",
"241 0xf1 frosty one \n",
"242 0xf2 frosty two \n",
"243 0xf3 frosty three \n",
"244 0xf4 frosty four \n",
"245 0xf5 frosty five \n",
"246 0xf6 frosty six \n",
"247 0xf7 frosty seven \n",
"248 0xf8 frosty eight \n",
"249 0xf9 frosty nine \n",
"250 0xfa frosty ann \n",
"251 0xfb frosty bet \n",
"252 0xfc frosty chris \n",
"253 0xfd frosty dot\n",
"254 0xfe frosty ernest\n",
"255 0xff frosty frost\n"
]
}
],
"source": [
"for i in range(256):\n",
" print(i, hex(i), magnusson(i))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.9"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment