首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在状态栏中显示十六进制值的二进制版本

在状态栏中显示十六进制值的二进制版本
EN

Stack Overflow用户
提问于 2014-11-26 17:48:41
回答 1查看 237关注 0票数 3

我现在正在做很多嵌入式C编程,这意味着我一直在写这样的东西:

代码语言:javascript
复制
(ioe_extra_A & 0xE7)

如果把我的光标放在0xE7上,emacs会在状态栏或迷你缓冲区中显示“0b11100111”,这样我就可以检查我的面具是什么意思了。

通常情况下,不管我希望emacs做什么,10分钟的谷歌搜索就会找到答案,但对于这个问题,我已经用尽了我的搜索技能,仍然没有找到答案。

提前谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-26 18:03:41

这似乎是可行的:

代码语言:javascript
复制
(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 for int-to-binary-string

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27155751

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档