八进制数字文字:什么时候?为什么?曾经? [英] Octal number literals: When? Why? Ever?

查看:11
本文介绍了八进制数字文字:什么时候?为什么?曾经?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从未在我的代码中使用八进制数,也没有遇到任何使用它的代码(尽管是十六进制和位旋转).

I have never used octal numbers in my code nor come across any code that used it (hexadecimal and bit twiddling notwithstanding).

我是在 1994 年左右开始使用 C/C++ 编程的,所以我可能还太年轻,不适合这个?旧代码是否使用八进制?C 通过在前面添加一个 0 来支持这些,但是使用这些以 8 为基数的数字文字的代码在哪里?

I started programming in C/C++ about 1994 so maybe I'm too young for this? Does older code use octal? C includes support for these by prepending a 0, but where is the code that uses these base 8 number literals?

推荐答案

我最近不得不编写访问 3 位字段的网络协议代码.当你想调试它时,八进制会派上用场.

I recently had to write network protocol code that accesses 3-bit fields. Octal comes in handy when you want to debug that.

为了效果,你能告诉我这个的 3 位字段是什么吗?

Just for effect, can you tell me what the 3-bit fields of this are?

0x492492

另一方面,这个相同的八进制数:

On the other hand, this same number in octal:

022222222

现在,最后,以二进制形式(3 个一组):

Now, finally, in binary (in groups of 3):

010 010 010 010 010 010 010 010

这篇关于八进制数字文字:什么时候?为什么?曾经?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆