> (define (bignum->u8vector/host-byte-order num) > (unless (bignum? num) (error "Argument is not a bignum!" num)) > > (let* ((word-size (cond-expand (64bit 8) (else 4))) ; Is there a better way? > (bignum-contents (##sys#slot num 1)) ; Digits preceded by sign word > (bignum-digits (substring bignum-contents word-size))) > (blob->u8vector/shared (string->blob bignum-digits))))
That's pretty fascinating. I wonder if you could even just C_copy_memory the bignum-contents+word into an existing blob of large enough size, instead of that substring/string->blob. Assuming you know your number is of fixed but >64 bit size, that is. (1024 bit for instance). If you didn't want native order, instead of C_copy_memory you could do a word based converter to network byte order called I dunno, C_copy_flipwords. Incidentally, chicken.h defines C_WORD_SIZE, and I think it's a fairly safe assumption even though the core never explicitly exports that value into scheme. You could probably do this pretty confidently: (define word-octets (/ (foreign-value "C_WORD_SIZE" integer) 8) _______________________________________________ Chicken-users mailing list Chicken-users@nongnu.org https://lists.nongnu.org/mailman/listinfo/chicken-users