在整数文字前导零的含义 [英] Meaning of leading zero in integer literal

查看:188
本文介绍了在整数文字前导零的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习用 C程序设计语言(第二版)

这是从 2.10赋值运算符和Ex pressions一个code段

1  /* bitcount() counts the number of 1-bits in its integer argument */
2  int bitcount(unsigned x)
3  {
4      int b;
5      for (b = 0; x != 0; x >>= 1)
6          if (x & 01)
7              b++;
8      return b;
9  }

我很困惑,为什么 X'放大器; 01 写在第6行,而不是 X'放大器; 1 X'放大器;为0x1 ?为 0 1 有必要吗?

I am confused why x & 01 is written in line 6 rather than x & 1 or x & 0x1? Is 0 before 1 necessary?

推荐答案

01也可以写成1,或为0x1。

The 01 could also be written 1, or 0x1.

01  = Octal Constant  Base 8 (1 Decimal)
1   = Decimal Constant. Base 10
0x1 = Hexadecimal Constant. Base 16 (1 Decimal).

在这本书的作者,基地8(八进制)在现有的计算机编程普遍。

When the book was written, Base 8 (octal) was pervasive in existing computer programming.

这篇关于在整数文字前导零的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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