home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
wp
/
bmacs.zip
/
HTOA.M
< prev
next >
Wrap
Text File
|
1989-01-01
|
2KB
|
76 lines
; Macro to convert a hexadecimal string to ASCII and insert it at the
; cursor position--contributed by Michael A. Fuller
;
; We at Solution Systems would like it if someone would take this,
; and adapt it to read a char from the current buffer and return the ASCII
; (integer) value of that character. That way, we'd have the rudiments
; of a hex-editing system (together with sprintf "%x")!
; Enter the hex values without spaces between them.
(macro htoa
(
(int h_count h_upper h_value h_pass h_rc)
(string work_string build_string out_string)
(save_position)
(if (get_parm 0 work_string "Enter hex values: ")
(
(if (!= 0 (% (strlen work_string) 2))
(
(error "Odd number of values. Please retry")
(restore_position)
)
;else
(
(while (< h_count (strlen work_string))
(
(= h_pass 0)
(while (<= h_pass 1)
(
(= h_value (atoi (substr work_string (+ (+ 1 h_pass) h_count) 1) 0))
(if (&& (>= h_value 48) (<= h_value 57))
(-= h_value 48)
;else
(
(if (&& (>= h_value 65) (<= h_value 70))
(-= h_value 55)
;else
(
(if (&& (>= h_value 97) (<= h_value 102))
(-= h_value 87)
;else
(
(error "Illegal value: %c" h_value)
(+= h_count (strlen work_string))
(= h_rc 1)
)
)
)
)
)
)
(if (== h_pass 0)
(= h_upper h_value)
)
(+= h_pass 1)
)
)
(sprintf build_string "%c" (+ h_value (* 16 h_upper)))
(+= out_string build_string)
(+= h_count 2)
)
)
(restore_position)
(if (== h_rc 0)
(insert out_string)
)
)
)
)
;else
(restore_position)
)
)
)