Public Group

Question about intergers and floating point.

This topic is 4951 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

#include <iostream>
using namespace std;

int main()
{
int one = 1;
int ten = 10;
int onehundred = 100;
int onethousand = 1000;
int tenthousand = 10000;
int onehundredthousand = 100000;
int million = 1000000;
int tenmillion = 10000000;
int onehundredmillion = 100000000;
int trillion = 1000000000;
int	tentrillion = 10000000000;
int	hundredtrillion  = 100000000000;

cout << one << endl;
cout << ten << endl;
cout << onehundred << endl;
cout << onethousand << endl;
cout << tenthousand << endl;
cout << onehundredthousand << endl;
cout << million << endl;
cout << tenmillion << endl;
cout << onehundredmillion << endl;
cout << trillion << endl;
cout << tentrillion << endl;
cout << hundredtrillion << endl;

double f_one = 1;
double f_ten = 10;
double f_onehundred = 100;
double f_onethousand = 1000;
double f_tenthousand = 10000;
double f_onehundredthousand = 100000;
double f_million = 1000000;
double f_tenmillion = 10000000;
double f_onehundredmillion = 100000000;
double f_trillion = 1000000000;
double	f_tentrillion = 10000000000;
double	f_hundredtrillion  = 100000000000;

cout << f_one << endl;
cout << f_ten << endl;
cout << f_onehundred << endl;
cout << f_onethousand << endl;
cout << f_tenthousand << endl;
cout << f_onehundredthousand << endl;
cout << f_million << endl;
cout << f_tenmillion << endl;
cout << f_onehundredmillion << endl;
cout << f_trillion << endl;
cout << f_tentrillion << endl;
cout << f_hundredtrillion << endl;

return 0;
}


What the program displays.
Quote:
 1 10 100 1000 10000 100000 1000000 10000000 100000000 1000000000 1410065408 1215752192 1 10 100 1000 10000 100000 1e+006 1e+007 1e+008 1e+009 1e+010 1e+011 Press any key to continue
I can't figure it out. Why do the integers fail to display the correct numbers while the floating points still yield the correct results even though in Sci Notation? Thx. Idea I still don't grasp.

Share on other sites
the max value for ints is 2147483647
and unsigned ints is 4294967296

this is because ints are 4 bytes
a byte is 8 bits
and a bit is 0 or 1
2^8 = 256
256^4 = 4294967296
2147483647 = 4294967296/2-1

edit: fixed more math

[Edited by - mike25025 on December 31, 2004 1:45:44 AM]

Share on other sites
Uhhh. It's not limited at 2147483647 or 4294967296.

Unsigned ints?

The last value decreased in value.

1410065408
1215752192

Sorry Didn't read rest of post. Reading now.

Share on other sites
its decreased because when a int (or other type) goes over its max it goes back to 0 (or its min) and then continues

unsinged int are ints that cant be negative

Share on other sites
Ok first. Unsigned Intergers. I've never heard of this.

I thought a byte could hold 0-255? Am I wrong? 256 values but 0 has to be included.???

Share on other sites
a byte holds

0
1
2
3
...

...
253
254
255

255-0 = 255
255+1 = 256

the 1 is added because 0 is in the list

0
1
2
3
4

4-0 = 4
4+1 = 5

there are five numbers

Share on other sites
byte = 0-255 if it is unsigned, if it is signed then, -128 to 127.

Share on other sites
Signed. OH OH OH. Haha.. Negated. Negative. Gotcha.

A int is usually 4 bytes?

So its

00000000000000000000000000000000

32 1/0's?

Strung together?

I just didn't get why you raised 8^2 = 256??/

Then 256^4 to get your values. I would have thought of it as

2^0 =1
2^1 =2
2^2 =4
.....8
.....16
.....32
.......64
........128

1+2+4+8+16+32+64+128=255

Then 255^4

But that's not working for some reason. Damn.

Share on other sites
unsigned 8 bit holds 0 - 255
signed 8 bit holds -128 - 127
unsigned 16 bit holds 0 - 65535
signed 16 bit holds -32768 - 32767

and so on...

whenever the value is larger or smaller, it wraps around.

meaning, in unsigned 8-bit:
255 + 1 = 0
0 - 1 = 255

Share on other sites
listing all the combination using 3 bits

1 000
2 001
3 010
4 011
5 100
6 101
7 110
8 111

there are 8 combinations

2(0 or 1)^3(the number of bits) = 8(the number of combinations)

edit: fixed math

1. 1
2. 2
Rutin
22
3. 3
4. 4
JoeJ
17
5. 5

• 14
• 30
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631774
• Total Posts
3002295
×