taocp

taocp sandbox.
git clone git://git.ricketyspace.net/taocp.git
Log | Files | Refs

commit 2b6938788cb269ad19ecfecf6c58bcdb067e3988
parent 46fa54c1a19b30e1d0f8d4067183461ed0859176
Author: rsiddharth <s@ricketyspace.net>
Date:   Tue,  8 Aug 2017 04:31:09 +0000

guile: Add (net ricketyspace taocp utils mix) module.

* guile/net/ricketyspace/taocp/utils/mix.scm: New file.

Diffstat:
guile/net/ricketyspace/taocp/utils/mix.scm | 25+++++++++++++++++++++++++
1 file changed, 25 insertions(+), 0 deletions(-)

diff --git a/guile/net/ricketyspace/taocp/utils/mix.scm b/guile/net/ricketyspace/taocp/utils/mix.scm @@ -0,0 +1,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))))