If you have the character set ' 0123456789'
in ASCII/Unicode and you want the digits to be mapped to their numeric values and space to be mapped to zero, then ord(c) & 0xf
does the trick.
This feels like something someone would have noticed already, but I have no idea how I could search for this.
@flowblok there's a similar trick for case conversion, also one of the design goals that EBDIC maintained, despite their other... bizarre choices.