(defvar BN←DIGIT←SIZE 32)

(when (eq 0 (getglobal  "BnDivideDigit"))
    (let ( (l #:system:path) f )
       (while (and l (null (probefile (setq f (catenate (car l) "kern.o")))))
          (nextl l))
       (ifn l
          (error 'kern "Je ne trouve pas kern.o dans le path" ())
          (cload f) )))

(unless (featurep 'kern)
	(add-feature 'kern)
	
(setfn 'BnSetToZero                 'subr3 (getglobal "BnSetToZero"))
(setfn 'BnAssign                    'nsubr (getglobal "BnAssign"))
(setfn 'BnSetDigit                  'subr3 (getglobal "BnSetDigit"))
(setfn 'BnGetDigit                  'subr2 (getglobal "BnGetDigit"))
(setfn 'BnNumDigits                 'subr3 (getglobal "BnNumDigits"))
(setfn 'BnNumLeadingZeroBitsInDigit 'subr2 (getglobal "BnNumLeadingZeroBitsInDigit"))
(setfn 'BnDoesDigitFitInWord        'subr2 (getglobal "BnDoesDigitFitInWord"))
(setfn 'BnIsDigitZero               'subr2 (getglobal "BnIsDigitZero"))
(setfn 'BnIsDigitNormalized         'subr2 (getglobal "BnIsDigitNormalized"))
(setfn 'BnIsDigitOdd                'subr2 (getglobal "BnIsDigitOdd"))
(setfn 'BnCompareDigits             'nsubr (getglobal "BnCompareDigits"))
(setfn 'BnComplement                'subr3 (getglobal "BnComplement"))
(setfn 'BnAndDigits                 'nsubr (getglobal "BnAndDigits"))
(setfn 'BnOrDigits                  'nsubr (getglobal "BnOrDigits"))
(setfn 'BnXorDigits                 'nsubr (getglobal "BnXorDigits"))
(setfn 'BnShiftLeft                 'nsubr (getglobal "BnShiftLeft"))
(setfn 'BnShiftRight                'nsubr (getglobal "BnShiftRight"))
(setfn 'BnAddCarry                  'nsubr (getglobal "BnAddCarry"))
(setfn 'BnAdd                       'nsubr (getglobal "BnAdd"))
(setfn 'BnSubtractBorrow            'nsubr (getglobal "BnSubtractBorrow"))
(setfn 'BnSubtract                  'nsubr (getglobal "BnSubtract"))
(setfn 'BnMultiplyDigit             'nsubr (getglobal "BnMultiplyDigit"))
(setfn 'BnDivideDigit               'nsubr (getglobal "BnDivideDigit"))
)

(defun BnAlloc (i)
   (makestring (mul 4 i) 0))

(defun BnCreate (Ad i)
   (let ( (n (makestring (mul 4 i) 0)) )
      (typestring n Ad)
      n ))

(defun BnFree (n) 1)

(defun BnGetType (n)
   (typestring n))

(defun BnSetType (n Ad)
   (typestring n Ad))

(defun BnGetSize (n)
   (logshift (slen n) -2))

(defvar #:KerN:tampon (BnCreate 'n 2))
(defun #:N:prin (s)
   (let ( cnt )
      (with ( (obase 16) )
         (for (i (sub1 (BnGetSize s)) -1 0)
            (BnAssign #:KerN:tampon 0 s i 1)
            (setq cnt 0)
            (while (< cnt BN←DIGIT←SIZE)
               (BnShiftLeft #:KerN:tampon 0 1 #:KerN:tampon 1 4)
               (prin (BnGetDigit #:KerN:tampon 1))
               (incr cnt 4) )))))