All pastes #739198 Raw Edit

[Vieira] Decimal to Hexadecimal

public text v1 · immutable
·published 2007-10-16 23:00 UTC
rendered paste body
(define (dec-to-hex d)
  (cond ((< d 10) (display d))
        ((= d 10) (display "A"))
        ((= d 11) (display "B"))
        ((= d 12) (display "C"))
        ((= d 13) (display "D"))
        ((= d 14) (display "E"))
        ((= d 15) (display "F"))
        (else (hex d))))
(define (hex d)
   (cond ((< (quotient d 16) 1) (dec-to-hex d))
      (else (hex (quotient d 16)) (if (< (remainder d 16) 10) (display (remainder d 16)) (dec-to-hex (remainder d 16))))))