bit.ascii2hex¶
if ascii is ‘0’-‘9’/’a’-‘f’/’A’-‘F’, set hex to that hexadecimal digit value (end error=0). else, set error=1.
ascii is bit[:8], hex in bit[:4], and error(output-param) is a bit.
Signature¶
def ascii2hex error, hex, ascii @ decimal_ascii_msh, uppercase_hexadecimal_ascii_msh, lowercase_hexadecimal_ascii_msh, return_error, check_uppercase_hex, check_lowercase_hex, dec_first_check, hex_first_check, hex_second_check, copy_decimal_value, copy_hexadecimal_value, nine4, seven3, two3, end { ... }
Defined in bit/casting.fj — lines 120–167 (view on GitHub).
Complexity¶
Time:
53@+86Space:
53@+86
See the complexity glossary for what @, w, dw, dbit, n mean.
Source¶
Click to view the macro body
def ascii2hex error, hex, ascii \
@ decimal_ascii_msh, uppercase_hexadecimal_ascii_msh, lowercase_hexadecimal_ascii_msh, return_error, \
check_uppercase_hex, check_lowercase_hex, dec_first_check, hex_first_check, hex_second_check, \
copy_decimal_value, copy_hexadecimal_value, nine4, seven3, two3, end {
.zero error
.zero 4, hex
.cmp 4, ascii+4*dw, decimal_ascii_msh, check_uppercase_hex, dec_first_check, check_uppercase_hex
check_uppercase_hex:
.cmp 5, ascii+3*dw, uppercase_hexadecimal_ascii_msh, check_lowercase_hex, hex_first_check, check_lowercase_hex
check_lowercase_hex:
.cmp 5, ascii+3*dw, lowercase_hexadecimal_ascii_msh, return_error, hex_first_check, return_error
dec_first_check:
.cmp 4, ascii, nine4, copy_decimal_value, copy_decimal_value, return_error
copy_decimal_value:
.xor 4, hex, ascii
;end
hex_first_check:
.inc 3, ascii
.cmp 3, ascii, two3, return_error, hex_second_check, hex_second_check
hex_second_check:
.cmp 3, ascii, seven3, copy_hexadecimal_value, copy_hexadecimal_value, return_error
copy_hexadecimal_value:
.xor 3, hex, ascii
.not hex+3*dw
;end
return_error:
.not error
;end
decimal_ascii_msh:
.vec 4, 0x30>>4
uppercase_hexadecimal_ascii_msh:
.vec 5, 0x40>>3
lowercase_hexadecimal_ascii_msh:
.vec 5, 0x60>>3
nine4:
.vec 4, 9
seven3:
.vec 3, 7
two3:
.vec 3, 2
end:
}
Depends on¶
← Previous: bit.ascii2dec