2009-10-20 165 views
2

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://download.plt-scheme.org/doc/372/html/mzscheme/mzscheme-Z-H-11.html#node_sec_11.2.1

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

回答

4

我不知道這是你要找的東西,或者即使你使用PLT,但如果這樣做,那麼你應該看看integer-bytes->integerinteger->integer-bytes在PLT中起作用are included。請注意,這些內容會創建二進制內容的字節字符串 - 因此它可能與您在此嘗試執行的操作不同。

(如果你正在使用的版本372,那麼你應該升級。)

+0

謝謝,我很驚訝,老師並沒有提及這 – yuguang

+0

好吧,如果這是一門功課的一部分,那麼你的老師可能需要你寫一個解決方案。 –