Created
May 31, 2012 02:24
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;; -*- 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