Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Given a challenge

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
SirSteez
Newbie cheater
Reputation: 0

Joined: 10 Nov 2007
Posts: 19

PostPosted: Thu Jan 31, 2008 12:48 am    Post subject: Given a challenge Reply with quote

My book told me to guess what these two pieces of code are supposed to do.
What do these codes do?
Unsigned integers aren't supposed to do anything, right?
Also, can somebody explain why instead of saying unsigned short int x; and unsigned short int y; it says the following?:

Code:
main()
{
     unsigned short x;
     unsigned short y;
     unsigned int z;
     z = x * y
}


and the second code
Code:
main()
{
     unsigned short Width;
     unsigned short Length;
     unsigned short Area;
     Area = Width * Length;
}
Back to top
View user's profile Send private message
goldengold
Grandmaster Cheater Supreme
Reputation: -1

Joined: 11 Nov 2006
Posts: 1841
Location: -.-

PostPosted: Thu Jan 31, 2008 1:10 am    Post subject: Reply with quote

Yea none of the integers have a falue so it doesent do anything -.-
Back to top
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger
SirSteez
Newbie cheater
Reputation: 0

Joined: 10 Nov 2007
Posts: 19

PostPosted: Thu Jan 31, 2008 1:13 am    Post subject: Reply with quote

goldengold wrote:
Yea none of the integers have a falue so it doesent do anything -.-

xD alright, thanks for clearing that up.
But it does lay out a formula. Would putting int infront of unsigned value INT x;
and same w/ y effect either?
Back to top
View user's profile Send private message
HolyBlah
Master Cheater
Reputation: 2

Joined: 24 Aug 2007
Posts: 446

PostPosted: Thu Jan 31, 2008 4:20 am    Post subject: Reply with quote

Code:
main()
{
     unsigned short Width;
     unsigned short Length;
     unsigned short Area;
     Area = Width * Length;
}

This one calculate areas.
Width and Length are unsigned because width and height can't be negative.
Back to top
View user's profile Send private message
SirSteez
Newbie cheater
Reputation: 0

Joined: 10 Nov 2007
Posts: 19

PostPosted: Thu Jan 31, 2008 5:12 pm    Post subject: Reply with quote

Ahh.. I see.
Wow solved problems in both of my threads.
Thanks again HolyBlah.
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8588
Location: 127.0.0.1

PostPosted: Thu Jan 31, 2008 6:30 pm    Post subject: Reply with quote

Unsigned versions of a variable type make it only able to hold a number between (and including) 0 and the max value of that data type. Negative values cannot be held in unsigned data types.

Quote:
Also, can somebody explain why instead of saying unsigned short int x; and unsigned short int y; it says the following?


Because you cannot assign a variable to two data types like that.
short is a data type as well as int.

The example uses shorts for the first two numbers then int for the second because the two shorts are being multiplied. The data types that are being used in your example are as follow:

unsigned short: 0 to 65535
unsigned int: 0 to 4294967295

If both the unsigned shorts held a number that would, when multiplied together, be greater then 65535 and the end result variable was a short as well, it would create an overflow error.

32768 * 2 would be the breaking point to cause an overflow with this.

Then two shorts at their max value, 65535 multipled together would be:

65535*65535 = 4294836225 which fits nicely into an unsigned int. Smile

Check out this page if you are still confused about data types an their unsigned versions:
http://www.cplusplus.com/doc/tutorial/variables.html

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
killersamurai
Expert Cheater
Reputation: 0

Joined: 10 Sep 2007
Posts: 197
Location: Colorado

PostPosted: Thu Jan 31, 2008 7:31 pm    Post subject: Reply with quote

When people use short instead of short int, it's because they're lazy. short int and short are the same. You can test it out if you like. All you have to do is put in the max value and add one. If it is signed, it will go negative and if it isn't, it will go to 0.

example
Code:

#include <iostream>

int main()
{
   unsigned short int a = 65536;
   unsigned short b = 65536;
   std::cout << a << "\n" << b;
   return 0;
}

When you run it, you will notice it will output 0 for both.

The same applies to long. long = long int.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Jan 31, 2008 7:36 pm    Post subject: Reply with quote

If you just use the general form "int", the compiler generally optimizes it to the lowest storage possible anyways. It all depends on what it sees you using that storage space for.
Back to top
View user's profile Send private message
SirSteez
Newbie cheater
Reputation: 0

Joined: 10 Nov 2007
Posts: 19

PostPosted: Sun Feb 03, 2008 1:15 pm    Post subject: Reply with quote

ohhh alright.
i didn't really get that short vs. short int
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites