[racket-dev] hex decoding?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Tue Jun 11 17:11:56 EDT 2013

Yes, I think file/sha1 is the right place.

Thanks!

Robby


On Tue, Jun 11, 2013 at 3:26 PM, David Vanderson
<david.vanderson at gmail.com>wrote:

> Thank you Stephen and Tony for your examples.  I found the following
> private function in db/private/mysql/connection.**rkt:
>
> (define (hex-string->bytes s)
>   (define (hex-digit->int c)
>     (let ([c (char->integer c)])
>       (cond [(<= (char->integer #\0) c (char->integer #\9))
>              (- c (char->integer #\0))]
>             [(<= (char->integer #\a) c (char->integer #\f))
>              (+ 10 (- c (char->integer #\a)))]
>             [(<= (char->integer #\A) c (char->integer #\F))
>              (+ 10 (- c (char->integer #\A)))])))
>   (unless (and (string? s) (even? (string-length s))
>                (regexp-match? #rx"[0-9a-zA-Z]*" s))
>     (raise-type-error 'hex-string->bytes
>                       "string containing an even number of hexadecimal
> digits" s))
>   (let* ([c (quotient (string-length s) 2)]
>          [b (make-bytes c)])
>     (for ([i (in-range c)])
>       (let ([high (hex-digit->int (string-ref s (+ i i)))]
>             [low  (hex-digit->int (string-ref s (+ i i 1)))])
>         (bytes-set! b i (+ (arithmetic-shift high 4) low))))
>     b))
>
>
> Can this function be exported?  I'm willing to make a patch with docs and
> tests - is file/sha1 the right place?
>
>
> Thanks,
> Dave
>
> _________________________
>  Racket Developers list:
>  http://lists.racket-lang.org/**dev <http://lists.racket-lang.org/dev>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/dev/archive/attachments/20130611/2123a40e/attachment.html>

Posted on the dev mailing list.