转换字节字符串的计划,以INT [英] Convert Byte String to Int in Scheme

查看:222
本文介绍了转换字节字符串的计划,以INT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有code这样的转换为十六进制字节的字符串

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")

我在想一个类似的功能将二进制转换成整数,然后打印出来。最终的结果是转换为十六进制二进制。一些有用的链接: 的http://download.plt-scheme.org/doc/372/html/mzscheme/mzscheme-Z-H-11.html#node_sec_11.2.1

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

<一个href="http://docs.plt-scheme.org/reference/bytestrings.html#%28def.%5F%28%28quote.%5F~23~25kernel%29.%5Fbytes-~3estring/utf-8%29%29" rel="nofollow">http://docs.plt-scheme.org/reference/bytestrings.html#(def.((quote.~23~25kernel)._bytes-~3estring/utf-8))

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

推荐答案

我不知道这是你要找的东西,或者即使你使用的 PLT ,但如果这样做,那么你应该看看整数bytes-&GT;的整数整型&GT;的整数,字节函数是在PLT包括。请注意,这些创建字节串用的的内容 - 因此它可能比你想在这里做什么不同的

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 and integer->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.

(如果你使用的是372版本,那么你就应该升级。)

(And if you're using version 372, then you should really upgrade.)

这篇关于转换字节字符串的计划,以INT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆