View previous topic :: View next topic |
Author |
Message |
supercharger Advanced Cheater
Reputation: 0
Joined: 06 Aug 2009 Posts: 61
|
Posted: Thu Nov 12, 2009 4:18 pm Post subject: which one is larger? 80 or 7F ? |
|
|
seems like in some program, 80 to FF are smaller than 00, therefore they are smaller than 01 to 7F .
but 7F + 01 = 80 right ?
i am confused.
|
|
Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Thu Nov 12, 2009 4:28 pm Post subject: |
|
|
It means the number is signed.
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
|
Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
|
Back to top |
|
 |
NoManchesPuto I post too much
Reputation: 0
Joined: 24 Jan 2009 Posts: 2820
|
Posted: Thu Nov 12, 2009 7:44 pm Post subject: |
|
|
Isn't 7F 7x15? So it would be larger right?
_________________
|
|
Back to top |
|
 |
smartz993 I post too much
Reputation: 2
Joined: 20 Jun 2006 Posts: 2013 Location: USA
|
Posted: Thu Nov 12, 2009 7:53 pm Post subject: |
|
|
GOGOGOGOGOGOGOGOGOGOGOGO! wrote: | Isn't 7F 7x15? So it would be larger right? |
No.
7F = 127.
|
|
Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Thu Nov 12, 2009 7:53 pm Post subject: |
|
|
0x7F = ( 7 * 16^1 + F * 16^0 )d
( 112 + 15 )d
127d
|
|
Back to top |
|
 |
NoManchesPuto I post too much
Reputation: 0
Joined: 24 Jan 2009 Posts: 2820
|
Posted: Thu Nov 12, 2009 8:06 pm Post subject: |
|
|
But I thought F was 15 in hexadecimal? o.O Some odd uh codes there lol...
Well sorry I couldn't help, I'm stilling learning hexes so ^^
_________________
|
|
Back to top |
|
 |
LolSalad Grandmaster Cheater
Reputation: 1
Joined: 26 Aug 2007 Posts: 988 Location: Australia
|
Posted: Thu Nov 12, 2009 11:31 pm Post subject: |
|
|
GOGOGOGOGOGOGOGOGOGOGOGO! wrote: | But I thought F was 15 in hexadecimal? o.O Some odd uh codes there lol...
Well sorry I couldn't help, I'm stilling learning hexes so ^^ |
F in hexadecimal is 15 in decimal. 10 in hexadecimal is 16 in decimal.
I guess you could think of 7F as 7×16+15 and 80 as 8×16+0 which are 127 and 128 respectively.
_________________
|
|
Back to top |
|
 |
kot1990 Expert Cheater
Reputation: 1
Joined: 06 Sep 2009 Posts: 131 Location: Greece
|
Posted: Sat Nov 14, 2009 7:08 pm Post subject: |
|
|
of course 0x80 is greater than 0x7F. In memory even if the variable is signed, negative numbers are in the range of 0x80 - 0xFF.
What changes is the way the program will display and handle the signed variable and make computations with other variables in the program.
Here's an example in C
Code: |
char var1 = 0x80; //This is signed; In memory it is 0x80
printf(%d,var1); //The output is -128;
BYTE var2 = 0x80; //This is unsigned; In memory it is again 0x80
printf("%d",var2); //But the output is 128;
printf("%d",var1 + var2); // 0x80 + 0x80 <- the output is 0;
printf("%d",var2 + var2); // 0x80 + 0x80 <- the output is 256;
|
As you see in memory the values look the same, but the program knows the type of every variable and treats it in different ways. So it has to do with the data type, if it is signed or unsigned
|
|
Back to top |
|
 |
mStorm Expert Cheater
Reputation: 0
Joined: 21 Feb 2009 Posts: 107
|
Posted: Tue Nov 24, 2009 5:11 pm Post subject: |
|
|
Take an 8-bit (one byte) integer for instance:
(0xFF) = 1111 1111 = Unsigned: 128, Signed: -1
The first bit determines whether or not the number is positive or negative... 1 = negative, 0 = positive.
Since 1000 0000 = 0x80, anything from 0x80-0xFF is going to be a negative number if the variable is signed.
To get the decimal value from that you would invert the bits and add one, then that is your negative number.
1000 0000 =
invert:
0111 1111
add 1:
0111 1111
+0000 0001
=1000 0000
=128 * -1
= -128
|
|
Back to top |
|
 |
|