hex.input_dec_uint¶
dst[:n] = the unsigned decimal number read from input (mod 16^n).
Reads ASCII ‘0’..’9’ until a ‘\n’ or ‘\0’ (EOF) terminator;
jumps to error on any other byte. Inverse of hex.print_dec_uint.
Signature¶
def input_dec_uint n, dst, error @ loop, valid_hi, terminator, digit_char, add_digit, digit, byte, end { ... }
Defined in hex/input.fj — lines 102–124 (view on GitHub).
Complexity¶
Time:
~ d(n(10@+39)) + (d+1)(7@+11) (d = number of input digits; estimate)Space:
~ n(9@+132) + 8@+100 (estimate)
See the complexity glossary for what @, w, dw, dbit, n mean.
Requires init¶
The following must be initialised before this macro is invoked:
hex.init
Source¶
Click to view the macro body
def input_dec_uint n, dst, error @ loop, valid_hi, terminator, digit_char, add_digit, digit, byte, end {
.zero n, dst
.zero n, digit
loop:
.input byte // byte = [low nibble, high nibble]
.if_flags byte+dw, (1<<0)|(1<<3), error, valid_hi // high nibble must be 0 (terminator) or 3 (digit)
valid_hi:
.if_flags byte+dw, 1<<3, terminator, digit_char
terminator:
.if_flags byte, (1<<0x0)|(1<<0xA), error, end // '\0' (0x00) or '\n' (0x0A)
digit_char:
.if_flags byte, (1<<10)-1, error, add_digit // low nibble must be 0..9
add_digit:
.mul10 n, dst
.zero digit
.xor digit, byte
.add n, dst, digit
;loop
digit: hex.vec n
byte: hex.vec 2
end:
}
Depends on¶
← Previous: hex.input_as_hex/3
Next: hex.input_dec_int →