如何在方案中将字符串转换为二进制
因此,我遇到了这个问题,我一直在尝试编码一种将二进制号码转换为方案(R5RS)字符串的方法,但是我一直在遇到一些问题。我和我的导师试图在一个小时的时间内解决它,但我们无法解决它。
实际上,截至我完成最后一场会议时,他抛弃了以下内容:
(define binary->string (lambda (lst)
(define str (make-string 0))
(letrec ((recurse (lambda (l)
; turn into not null
(if (null? l)
(lambda ()
(set! str (string-append str (number->string (car l))))
(recurse (cdr l)))
)
)
)
)
(recurse lst)
)
str)
)
(binary->string '(0 1 0 1 0 0 1 1))
看看它说“变成无效”的地方?好吧,我们遇到了一些问题,试图将数字转换为无效。我肯定希望这会有所帮助。谢谢!
So, I've ran into this problem where I've been trying to code a means to convert a binary number to a string in Scheme (R5RS), but I've been having some....problems. My tutor and I tried to solve it over the course of an hour, but we haven't been able to solve it.
In fact, as of the time I finished the last session, he left behind the following:
(define binary->string (lambda (lst)
(define str (make-string 0))
(letrec ((recurse (lambda (l)
; turn into not null
(if (null? l)
(lambda ()
(set! str (string-append str (number->string (car l))))
(recurse (cdr l)))
)
)
)
)
(recurse lst)
)
str)
)
(binary->string '(0 1 0 1 0 0 1 1))
See where it says "turn into not null"? Well, we've had some problems trying to convert the number into not null. I sure hope this helps. Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以你想要这个结果吗?
我看到您已经使用过 string-append 和
number-> string
,因此您还应使用apply
和map
:如果您也想将其转换为小数号,请使用
< /a>带有 radix 2:string- string- string- string- string-&gt;数字
So you want this result?
I see you've already used
string-append
andnumber->string
, so you should also useapply
andmap
:If you also want to convert it into decimal number, use
string->number
with radix 2: