Skip to content

Instantly share code, notes, and snippets.

@alcidesfp
Created May 31, 2012 02:24
Show Gist options
  • Save alcidesfp/2840525 to your computer and use it in GitHub Desktop.
Save alcidesfp/2840525 to your computer and use it in GitHub Desktop.
Función de conversión de números decimales a hexadecimales en Scheme
;; -*- coding:utf-8; mode:scheme -*-
(define (dec->hex num) ;; versión iterativa con DO
"Función de conversión de números decimales a hexadecimales"
(if (and (integer? num)(>= num 0)) ;; def solo para enteros positivos
(let ((base 16)
(cifras-hex "0123456789ABCDEF"))
(do ((cantidad num (quotient cantidad base))
(retval '() (cons (string-ref cifras-hex (remainder cantidad base))
retval)))
((= cantidad 0)(if (null? retval) "0" (list->string retval))) ))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment