comparison lisp/tl/tl-num.el @ 118:7d55a9ba150c r20-1b11

Import from CVS: tag r20-1b11
author cvs
date Mon, 13 Aug 2007 09:24:17 +0200
parents c0c698873ce1
children
comparison
equal deleted inserted replaced
117:578fd4947a72 118:7d55a9ba150c
1 ;;; 1 ;;;
2 ;;; $Id: tl-num.el,v 1.2 1996/12/28 21:03:10 steve Exp $ 2 ;;; $Id: tl-num.el,v 1.3 1997/04/05 19:32:20 steve Exp $
3 ;;; 3 ;;;
4 ;;; by MORIOKA Tomohiko <morioka@jaist.ac.jp>, 1993/10/4 4 ;;; by MORIOKA Tomohiko <morioka@jaist.ac.jp>, 1993/10/4
5 ;;; 5 ;;;
6 6
7 (require 'emu) 7 (require 'emu)
9 9
10 10
11 ;;; @ n base 11 ;;; @ n base
12 ;;; 12 ;;;
13 13
14 (defun char-to-int (chr) 14 (defun n-char-to-int (chr)
15 "Convert n base character CHR to integer (n <= 36). [tl-num]" 15 "Convert n base character CHR to integer (n <= 36). [tl-num]"
16 (cond ((and (<= ?0 chr)(<= chr ?9)) (- chr ?0)) 16 (cond ((and (<= ?0 chr)(<= chr ?9)) (- chr ?0))
17 ((and (<= ?A chr)(<= chr ?Z)) (+ (- chr ?A) 10)) 17 ((and (<= ?A chr)(<= chr ?Z)) (+ (- chr ?A) 10))
18 ((and (<= ?a chr)(<= chr ?z)) (+ (- chr ?a) 10)) 18 ((and (<= ?a chr)(<= chr ?z)) (+ (- chr ?a) 10))
19 )) 19 ))
20 20
21 (defun int-to-char (n) 21 (defun int-to-n-char (n)
22 "Convert integer N to n base character (n <= 36). [tl-num]" 22 "Convert integer N to n base character (n <= 36). [tl-num]"
23 (if (< n 10) 23 (if (< n 10)
24 (+ ?0 n) 24 (+ ?0 n)
25 (+ ?A (- n 10)) 25 (+ ?A (- n 10))
26 )) 26 ))
35 35
36 (defun base-char-seq-to-int (base seq) 36 (defun base-char-seq-to-int (base seq)
37 "Convert n base char sequence SEQ to number. [tl-num]" 37 "Convert n base char sequence SEQ to number. [tl-num]"
38 (foldl (function 38 (foldl (function
39 (lambda (n chr) 39 (lambda (n chr)
40 (+ (* n base)(char-to-int chr)) 40 (+ (* n base)(n-char-to-int chr))
41 )) 41 ))
42 0 seq)) 42 0 seq))
43 43
44 44
45 ;;; @ Hex 45 ;;; @ Hex
50 (cond ((and (<= ?0 chr)(<= chr ?9)) (- chr ?0)) 50 (cond ((and (<= ?0 chr)(<= chr ?9)) (- chr ?0))
51 ((and (<= ?A chr)(<= chr ?F)) (+ (- chr ?A) 10)) 51 ((and (<= ?A chr)(<= chr ?F)) (+ (- chr ?A) 10))
52 ((and (<= ?a chr)(<= chr ?f)) (+ (- chr ?a) 10)) 52 ((and (<= ?a chr)(<= chr ?f)) (+ (- chr ?a) 10))
53 )) 53 ))
54 54
55 (defalias 'number-to-hex-char 'int-to-char) 55 (defalias 'number-to-hex-char 'int-to-n-char)
56 56
57 (defun hex-seq-to-int (seq) 57 (defun hex-seq-to-int (seq)
58 "Convert hex number sequence SEQ to integer. [tl-num]" 58 "Convert hex number sequence SEQ to integer. [tl-num]"
59 (base-seq-to-int 16 seq) 59 (base-seq-to-int 16 seq)
60 ) 60 )