Convert byte string to int in schema

I have code like this for converting hex to byte string

(define (word->bin s) (let ((n (string->number s))) (bytes (bitwise-and (arithmetic-shift n -24) #xFF) (bitwise-and (arithmetic-shift n -16) #xFF) (bitwise-and (arithmetic-shift n -8) #xFF) (bitwise-and n #xFF)))) (word->bin "#x10000002") 

I am thinking of a similar function to convert binary code to integers, and then print it. The end result is binary code converted to hex. Some useful links: http://download.plt-scheme.org/doc/372/html/mzscheme/mzscheme-ZH-11.html#node_sec_11.2.1

http://docs.plt-scheme.org/reference/bytestrings.html# (def. ((quote. ~ 23 ~ 25kernel). _bytes- ~ 3estring / UTF-8))

+2
algorithm byte scheme bytestring
Oct 20 '09 at 21:52
source share
1 answer

I'm not sure if this is what you are looking for, or even if you are using PLT , but if you do, then you should look at the integer-bytes->integer and integer->integer-bytes functions that are included in the PLT. Note that they create byte strings with binary content - so it may be different from what you are trying to do here.

(And if you are using version 372, then you really need to upgrade.)

+4
Oct 20 '09 at 10:15
source share



All Articles