blob: c92a61b1ca86f9fba3356b8cd3db14df89d08c09 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
;;;; copyright 2016 rsiddharth <s@ricketyspace.net>
;;;; under gnu general public license version 3 or higher.
(define-module (net ricketyspace taocp utils mix)
#:use-module (srfi srfi-13)
#:use-module (srfi srfi-1)
#:export (word-to-decimal
nth-byte))
;;;; Functions that facilitate hacking in MIX
;;; All functions in this module assume that a byte is 6 bits.
(define (word-to-decimal word)
"Converts WORD to a decimal number.
WORD must be a string in this format:
±:00:00:00:00:00"
(let ((bytes (string-split word #\:)))
(fold (lambda (byte-number d)
(+ (* (expt (expt 2 6) (- 4 byte-number))
(string->number (list-ref bytes byte-number)))
d))
0 (iota 5))))
|