Function: math-format-twos-complement

math-format-twos-complement is a byte-compiled function defined in calc-bin.el.gz.

Signature

(math-format-twos-complement A)

Documentation

Format an integer in two's complement mode.

Source Code

;; Defined in /usr/src/emacs/lisp/calc/calc-bin.el.gz
;;; Two's complement mode

(defun math-format-twos-complement (a)
  "Format an integer in two's complement mode."
  (when (zerop calc-word-size)
    (error "Nonzero word size required"))
  (let* (;(calc-leading-zeros t)
         (num
          (cond
           ((or (eq a 0)
                (Math-integer-posp a))
            (math-format-radix a))
           ((Math-integer-negp a)
            (let ((newa (math-add a math-2-word-size)))
              (math-format-radix newa))))))
    (let* ((calc-internal-prec 6)
           (digs (math-compute-max-digits (math-abs calc-word-size)
                                          calc-number-radix))
           (len (length num)))
      (if (< len digs)
          (setq num (concat (make-string (- digs len) ?0) num))))
    (when calc-group-digits
      (setq num (math-group-float num)))
    (concat
     (number-to-string calc-number-radix)
     "##"
     num)))