You are here

Does Tinyscheme support radix (base)?

It would seem that Tinyscheme does not support the radix.

Per the Scheme specs at there is a radix parameter, such that if I code

(number->string 255 16)

I would expect it to return the string "ff".

I tried the attached code (which puts a script "Test Base 16" into a "Debug" menu). I'm expecting the code to put "ff" into the image as a text layer, but it puts "255" in. My ultimate goal is to convert an RGB value 0-255 0-255 0-255 into a Web hex value. Any ideas?

GIMP 2.6.6

Charles Belov

testBase16.scm969 bytes

Unfortunately, TinyScheme does not implement the radix argument as prescribed by R5RS. You could use the following function to convert numbers in the range of 0-255 to hexadecimal strings (00-FF, change the "55" to "87" for lowercase alphas). (define (byte->hexstr x) (define (nyb->hex x) (if (> x 9) (integer->char (+ 55 x)) (integer->char (+ 48 x)))) (string-append (make-string 1 (nyb->hex (trunc (/ x 16)))) (make-string 1 (nyb->hex (modulo x 16)))))
Subscribe to Comments for "Does Tinyscheme support radix (base)?"