Please HELP:Hexadecimal conversion error???? 
Author Message
 Please HELP:Hexadecimal conversion error????

can this be true? (taken from my debug window):

?print hex(sc_close)
F060

print sc_close
-4000

print hex(wptemp)
F060

print wptemp
 61536
?

How come the same value in Hex notation (&HF060) be a diferent value in
decimal notation?
sc_close is a public const and wptemp is a Long Var.

Can anybody please expalin this to me?
--
_______________________________________
JOEL PAULA                   TECNILAB PORTUGAL
_______________________________________



Fri, 19 Mar 1999 03:00:00 GMT  
 Please HELP:Hexadecimal conversion error????


Quote:
>can this be true? (taken from my debug window):
>print hex(sc_close)     F060
>print sc_close          -4000
>print hex(wptemp)       F060
>print wptemp            61536
>How come the same value in Hex notation (&HF060) be a diferent value in
>decimal notation?  sc_close is a public const and wptemp is a Long Var.

Yes, it can be true...

    sc_close is defined as a 2-byte value, and because the high-order
         bit is set (as part of the 'F') it is a negative number

    wptemp is a long int and is really stored as 0000F060; because
         the high-order bit is off (as part of the leading '0') it is
         a positive number.

Bob Hilton



Fri, 19 Mar 1999 03:00:00 GMT  
 Please HELP:Hexadecimal conversion error????



Quote:
> print sc_close
> -4000
> print wptemp
>  61536
> JOEL PAULA                   TECNILAB PORTUGAL
> _______________________________________

sc_close is a word , vb didnt know unsigned word
wptemp is a long so it was the same value but one is signed and the other
not.


Sat, 20 Mar 1999 03:00:00 GMT  
 Please HELP:Hexadecimal conversion error????

Quote:

> =
> can this be true? (taken from my debug window):
> =ABprint hex(sc_close)
> F060
> print sc_close
> -4000
> print hex(wptemp)
> F060
> print wptemp
>  61536
> How come the same value in Hex notation (&HF060) be a diferent value
> in decimal notation?
> sc_close is a public const and wptemp is a Long Var.
> =
> Can anybody please expalin this to me?

The values are the same if counting with 16 bit integers. It seems that
Public Const converts the value to the least integer that contains
the value.

Peter Larsson



Sat, 20 Mar 1999 03:00:00 GMT  
 Please HELP:Hexadecimal conversion error????

Quote:

> The values are the same if counting with 16 bit integers. It seems that
> Public Const converts the value to the least integer that contains
> the value.

Although you can override this by using a type declaration character,
forcing the constant to be a Long value for instance, even if it would
otherwise be typed as a byte or integer...

Tony Hamilton



Sat, 20 Mar 1999 03:00:00 GMT  
 Please HELP:Hexadecimal conversion error????

I found the solution myself. I have to tell VB to define the SC_CLOSE
constant value as unsigned.
        Public Const SC_CLOSE = &HF060&
The last "&" makes it an unsigned value. I found out that giving a
Hexadecimal value is the same as defining a variable in binary. Such way,
the MSB in the number is the sign bit, this way "&F060" is the same as
"&0000F060". This means that the MSB is a 0 - signing the number as a
negative value.

For more explanation, take a look at the first answer in this thread.

Bye!
--
_______________________________________
JOEL PAULA                   TECNILAB PORTUGAL
_______________________________________



Quote:
> can this be true? (taken from my debug window):

> ?print hex(sc_close)
> F060

> print sc_close
> -4000

> print hex(wptemp)
> F060

> print wptemp
>  61536
> ?

> How come the same value in Hex notation (&HF060) be a diferent value in
> decimal notation?
> sc_close is a public const and wptemp is a Long Var.

> Can anybody please expalin this to me?
> --
> _______________________________________
> JOEL PAULA                   TECNILAB PORTUGAL
> _______________________________________



Sun, 21 Mar 1999 03:00:00 GMT  
 Please HELP:Hexadecimal conversion error????

Quote:


> > can this be true? (taken from my debug window):
> > ?print hex(sc_close)
> > F060
> > print sc_close
> > -4000
> > print hex(wptemp)
> > F060
> > print wptemp
> >  61536
> > How come the same value in Hex notation (&HF060) be a diferent value
> > in decimal notation?
> > sc_close is a public const and wptemp is a Long Var.

> > Can anybody please expalin this to me?

> The values are the same if counting with 16 bit integers. It seems that
> Public Const converts the value to the least integer that contains
> the value.

As Peter points out, VB automatically selects the smallest data type
that will hold the value.  In this case it is Integer.  But the Integer
data type is SIGNED.  With a 16 bit data area, this means that
&H0000-&H7FFF is used for positive values, and &H8000-&HFFFF is used for
negative; hence, &HF060 returns -4000 in decimal.

The Long data type is also SIGNED, but is 32 bits wide.  Hence, the
positive values are &H00000000-&H7FFFFFFF, and the negatives are
&H80000000-&HFFFFFFFF.  So, &HF060 is interpreted as &H0000F060, which
is the positive value 61536.

I would suggest declaring the value for the constant in decimal
notation, rather than hex.  That will force the data type to a Long.
(It may work to specify leading zeros, as well: &H0000F060)

Craig Warford
WAR



Sun, 21 Mar 1999 03:00:00 GMT  
 Please HELP:Hexadecimal conversion error????

Quote:

> I found the solution myself. I have to tell VB to define the SC_CLOSE
> constant value as unsigned.
>         Public Const SC_CLOSE = &HF060&
> The last "&" makes it an unsigned value. I found out that giving a

Not quite.  The last "&" forces the constant to a LONG data type (just
like "%" forces an INTEGER type - search online help for "Long Data
Type"), but it still has a sign.  The values with a sign start at a
higher hex range, specifically, &80000000-&FFFFFFFF instead of
&8000-&FFFF.

Still, it looks like a usable solution, provided you don't ever define
the constant to be anything greater than &7FFFFFFF.  If you do, you'll
have to change the data type declaration character again.

Craig Warford
WAR



Mon, 22 Mar 1999 03:00:00 GMT  
 Please HELP:Hexadecimal conversion error????

Another solution, using VB 4 is to explicitly type the constant:

Public Const SC_CLOSE As Long = &HFO60



Quote:
> I found the solution myself. I have to tell VB to define the SC_CLOSE
> constant value as unsigned.
>    Public Const SC_CLOSE = &HF060&



Tue, 23 Mar 1999 03:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Please HELP:Hexadecimal conversion error????

2. Please HELP:Hexadecimal conversion error????

3. Please HELP:Hexadecimal conversion error????

4. Please HELP:Hexadecimal conversion error????

5. Help, please please please!!!! Inputing a Hexadecimal Number

6. PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP, PLEASE HELP,

7. Please help! A97-A2000 Conversion error

8. Data Type Conversion Error with Long Binary Field -PLEASE HELP

9. PLEASE HELP: Type mismatch error with byte conversion

10. please help with date conversion error 4 collection.

11. PLEASE HELP: Type mismatch error with byte conversion

12. PLEASE HELP: Type mismatch error with byte conversion

 

 
Powered by phpBB® Forum Software