3

私は現在、多くの組み込み C プログラミングを行っています。つまり、常に次のようなことを書いています。

(ioe_extra_A & 0xE7)

カーソルを 0xE7 に置くと、emacs がステータス バーまたはミニ バッファーに "0b1110 0111" を表示するので、マスクが意図したとおりであることを確認できれば、非常に便利です。

通常、私が emacs に何をさせたいとしても、10 分間のグーグル検索で答えが得られますが、これについては、検索スキルを使い果たしたにもかかわらず、まだ答えが得られていません。

事前に感謝します。

4

1 に答える 1

3

これはうまくいくようです:

(defvar my-hex-idle-timer nil)

(defun my-hex-idle-status-on ()
  (interactive)
  (when (timerp my-hex-idle-timer)
    (cancel-timer my-hex-idle-timer))
  (setq my-hex-idle-timer (run-with-idle-timer 1 t 'my-hex-idle-status)))

(defun my-hex-idle-status-off ()
  (interactive)
  (when (timerp my-hex-idle-timer)
    (cancel-timer my-hex-idle-timer)
    (setq my-hex-idle-timer nil)))

(defun int-to-binary-string (i)
  "convert an integer into it's binary representation in string format
By Trey Jackson, from https://stackoverflow.com/a/20577329/."
  (let ((res ""))
    (while (not (= i 0))
      (setq res (concat (if (= 1 (logand i 1)) "1" "0") res))
      (setq i (lsh i -1)))
    (if (string= res "")
        (setq res "0"))
    res))

(defun my-hex-idle-status ()
  (let ((word (thing-at-point 'word)))
    (when (string-prefix-p "0x" word)
      (let ((num (ignore-errors (string-to-number (substring word 2) 16))))
    (message "In binary: %s" (int-to-binary-string num))))))

入力M-x my-hex-idle-status-onしてオンにします。

前述のように、Trey Jacksonに感謝しint-to-binary-stringます。

于 2014-11-26T18:03:41.703 に答える