在Scheme中将字节字符串转换为Int
我有这样的代码将十六进制转换为字节字符串
(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")
我正在考虑一个类似的函数将二进制转换为整数,然后打印它。最终结果是将二进制转换为十六进制。一些有用的链接: http://下载。 plt-scheme.org/doc/372/html/mzscheme/mzscheme-ZH-11.html#node_sec_11.2.1
I have code like this to convert hex into 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'm thinking of a similar function to convert binary into integers, then print it. The end result is the binary translated to hex. Some helpful links:
http://download.plt-scheme.org/doc/372/html/mzscheme/mzscheme-Z-H-11.html#node_sec_11.2.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定这是否是您要寻找的,或者即使您正在使用 PLT,但如果你这样做,那么你应该看看 包含在 PLT 中。请注意,这些创建具有二进制内容的字节字符串 - 因此它可能与您在此处尝试执行的操作不同。
(如果您使用的是 372 版本,那么您确实应该升级。)
I'm not sure that this is what you're looking for, or even if you're using PLT, but if you do, then you should look at the
integer-bytes->integer
andinteger->integer-bytes
functions that are included in PLT. Note that these create byte strings with binary content -- so it might be different than what you're trying to do here.(And if you're using version 372, then you should really upgrade.)