Welcome to the CHICKEN Scheme pasting service

copy version ##sys#char->utf8-string added by liao on Mon Dec 13 15:47:36 2021

(import (chicken fixnum))

(define (ichar->utf8-string c)
  (print c)
  (let ([i (char->integer c)])
    (cond [(fx<= i #x7F)
           (string c) ]
          [(fx<= i #x7FF)
           (string (integer->char (fxior #b11000000 (fxshr i 6)))
	           (integer->char (fxior #b10000000 (fxand i #b111111)))) ]
          [(fx<= i #xFFFF)
           (string (integer->char (fxior #b11100000 (fxshr i 12)))
	           (integer->char (fxior #b10000000 (fxand (fxshr i 6) #b111111)))
	           (integer->char (fxior #b10000000 (fxand i #b111111)))) ]
          [(fx<= i #x1FFFFF)
           (string (integer->char (fxior #b11110000 (fxshr i 18)))
	           (integer->char (fxior #b10000000 (fxand (fxshr i 12) #b111111)))
	           (integer->char (fxior #b10000000 (fxand (fxshr i 6) #b111111)))
	           (integer->char (fxior #b10000000 (fxand i #b111111)))) ]
          [else
           (error "UTF-8 codepoint out of range:" i) ] ) ) )

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Type in the text below:
       _                      
  __ _| |___  _____ _ __ ___  
 / _` | __\ \/ / __| '_ ` _ \ 
| (_| | |_ >  < (__| | | | | |
 \__,_|\__/_/\_\___|_| |_| |_|
                              
Visually impaired? Let me spell it for you (wav file) download WAV