如何将零设置为整数? [英] How do i set zero as a Integer?
问题描述
我的意思是,任何跟随0的东西都会自动变成八进制
数。我希望有一个整数变量,即使它们以零开头,也会将数字保存为
整数。
例如:
int 08453
如果我试图在其上使用printf(),而不是某些八进制
数字,则
应该打印08453。 />
谢谢。
gk245aécrit:我的意思是,任何事情跟随0会自动变成八进制数。
严重措辞。
<<跟随0的任何内容会自动解释为
文本八进制数的表示。>>
我希望有一个整数变量,即使它们以零开头也会将数字保存为整数。
>例如:
int 08453
这不是C.你是什么意思?
int x = 08453;
? ''无效的八进制表示''
int x = 8453;
是有效的十进制表示。
应该打印08453,如果我试图使用printf(),而不是一些八进制数字。
如何让这个领先0源代码?
-
A +
Emmanuel Delahaye
gk245写道:
我的意思是,任何跟随0的东西都会自动变成八进制数字。我想要一个整数变量,即使它们以零开头,也会将数字保存为整数。
我不确定我理解你认为是什么问题,因为整数
变量/总是/将值存储为整数,但是让'''试试这个:
例如:
int 08453
这在C中没有意义。你的意思是:
int i = 08453;
如果我试图使用printf()打印08453,而不是一些
八进制数。
在这种情况下你应该写下以下任何一种:
int i = 8453;
int i = 020405;
int i = 0x2105;
整数变量包含整数/值/。这与
整数/常数/(文字)不同,它们可以用不同的
基数表示。以下所有内容都是等价的:
int i = 07;
int i = 0x7;
int i = 7;
他们都将值7(七个,如七个苹果)分配给i。这个
的意思是,当你使用printf()打印`i`时,无论你指定的格式是什么,你都可以获得它的/ value / out $
>
printf("%d \ n",i); / *十进制* /
printf("%x \ n",i); / * hex;它是/不是/先于0x,但* /
...
所以,你可以任意方式拥有它,真的。
-
BR,弗拉基米尔
沟通方面的每一次进步都会让人感觉更糟糕。 />
- Frank Moore Colby
Vladimir S. Oka写道:
gk245写道:
我的意思是,任何跟随0的东西都会自动变成
八进制数。我想要一个整数变量,即使它们以零开头也会将数字保存为整数。
我不确定我是否理解你认为的问题,如整数
变量/ always /将值存储为整数,但让我们试试这个:
例如:
int 08453
这在C中没有意义。你的意思是:
int i = 08453;
D''哦!你抓住我了!以上不是有效的八进制数。
八进制数字仅为[0..7]。其他一切仍然存在,但是......
在这种情况下你应该写下以下任何一种:
int i = 8453;
int i = 020405;
int i = 0x2105;
整数变量包含整数/值/。这与
整数/常量/(文字)不同,它们可以用不同的基础表示。以下所有内容都是等价的:
int i = 07;
int i = 0x7;
int i = 7;
它们都赋值7 (七,如在七个苹果中)到i。这意味着,当您使用printf()打印`i`时,无论您指定的格式是什么,都可以获得/ value / out:
printf("%d \\ \
",i)的; / * decimal * /
printf("%x \ n",i); / * hex;它是/不是/先于0x,但* /
...
所以,你可以以任何你想要的方式拥有它,真的。
-
BR,Vladimir
另一个晚上不要睡在桉树上。
I mean, anything that follows a 0 is automatically turned into a octal
number. I want to have a integer variable that will hold numbers as
integers even if they begin with a zero.
for example:
int 08453
should print 08453 if i tried to use printf() on it, and not some octal
number.
Thanks.
gk245 a écrit :I mean, anything that follows a 0 is automatically turned into a octal
number.
Badly phrased.
<<anything that follows a 0 is automatically interpreted like the
textual representation of an octal number.>>
I want to have a integer variable that will hold numbers as
integers even if they begin with a zero.
for example:
int 08453
This is not C. What do you meant ?
int x = 08453;
? ''Invalid octal representation''
int x = 8453;
Is a valid decimal representation.
should print 08453 if i tried to use printf() on it, and not some octal
number.
How is it important to you to have this leading 0 in a source code ?
--
A+
Emmanuel Delahaye
gk245 wrote:
I mean, anything that follows a 0 is automatically turned into a octal
number. I want to have a integer variable that will hold numbers as
integers even if they begin with a zero.
I''m not sure I understand what you think is the problem, as integer
variables /always/ store values as integers, but let''s try this:
for example:
int 08453
This has no meaning in C. Did you mean:
int i = 08453;
should print 08453 if i tried to use printf() on it, and not some
octal number.
In which case you should have written either of these:
int i = 8453;
int i = 020405;
int i = 0x2105;
An integer variable holds an integer /value/. This is different from
integer /constants/ (literals) which can be represented in different
bases. All the following are equivalent:
int i = 07;
int i = 0x7;
int i = 7;
They all assign value 7 (seven, as in "seven apples") to `i`. This
means, when you print `i` using printf(), you get its /value/ out in
whatever format you specify:
printf("%d\n",i); /* decimal */
printf("%x\n",i); /* hex; it''s /not/ preceeded by 0x, though */
...
So, you can have it any way you want it, really.
--
BR, Vladimir
Every improvement in communication makes the bore more terrible.
-- Frank Moore Colby
Vladimir S. Oka wrote:
gk245 wrote:I mean, anything that follows a 0 is automatically turned into a
octal
number. I want to have a integer variable that will hold numbers as
integers even if they begin with a zero.
I''m not sure I understand what you think is the problem, as integer
variables /always/ store values as integers, but let''s try this:for example:
int 08453
This has no meaning in C. Did you mean:
int i = 08453;
D''oh! You caught me out here! The above is not a valid octal number.
Octal digits are [0..7] only. Everything else still holds, though...
In which case you should have written either of these:
int i = 8453;
int i = 020405;
int i = 0x2105;
An integer variable holds an integer /value/. This is different from
integer /constants/ (literals) which can be represented in different
bases. All the following are equivalent:
int i = 07;
int i = 0x7;
int i = 7;
They all assign value 7 (seven, as in "seven apples") to `i`. This
means, when you print `i` using printf(), you get its /value/ out in
whatever format you specify:
printf("%d\n",i); /* decimal */
printf("%x\n",i); /* hex; it''s /not/ preceeded by 0x, though */
...
So, you can have it any way you want it, really.
--
BR, Vladimir
Another good night not to sleep in a eucalyptus tree.
这篇关于如何将零设置为整数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!