comparisons between decimal and hex values doesn't seem to work 
Author Message
 comparisons between decimal and hex values doesn't seem to work

I know this sounds crazy but when I compare a variable with a value in it to
the value in hex form (0x...) the comparison fails even though I know that
this comparison is true.  When I compare it to the same value in decimal
form, the comparison succeeds.  What the hell?  Is there something wrong
with the current version of JScript that I can fix by getting a patch or
something?
please respond to the address as I do not check newsgroups often.
any help appreciated,
brian



Sun, 02 Dec 2001 03:00:00 GMT  
 comparisons between decimal and hex values doesn't seem to work
Check the types of the things you're testing.  With the implicit type
conversions that are going on, sometimes you're comparing a string with a
number, etc.


Quote:
> I know this sounds crazy but when I compare a variable with a value in it
to
> the value in hex form (0x...) the comparison fails even though I know that
> this comparison is true.  When I compare it to the same value in decimal
> form, the comparison succeeds.  What the hell?  Is there something wrong
> with the current version of JScript that I can fix by getting a patch or
> something?
> please respond to the address as I do not check newsgroups often.
> any help appreciated,
> brian




Sun, 02 Dec 2001 03:00:00 GMT  
 comparisons between decimal and hex values doesn't seem to work
Hi,

the HRESULT return codes like OLE-DB error 0x80040E09 "Permission denied"
are equivalent to VB 32-bit signed integers, here -2147217911 whereas
JScript follows the ECMA implementing IEEE754 floating point format which
has a mantissa of +- 2^53 (unsigned!).

Here is my error interpretation function from a previous message that
compensates this:

// hide the current scripting host
//
****************************************************************************
 function writeln(s) { WScript.Echo(s) }        // WSH *
// function writeln(s) { Response.Write(s) }       // ASP *
// function writeln(s) { document.write(s + '\n') }     // DOM *
//
****************************************************************************

// -------------------------------------------------------------------------
---
// constructor function
//
// HRESULT format definition from:
// http://msdn.microsoft.com/library/sdkdoc/com/error_5g6r.htm
// -------------------------------------------------------------------------
---

function ErrorCode(n) {
 // convert the number to a 32-bit quantity fitting into the mantissa
 var errorCode = ((n < 0) ? n + Math.pow(2, 32) : n) & 0xffffffff;
 // unsigned to signed integer
 this.error = (n > Math.pow(2, 31) - 1) ? n - Math.pow(2, 32) : n;
 // bit 31
 this.severity = errorCode >>> 31;
 // bits 30 .. 27 are reserved for R, C, N, r
 // bits 26 .. 16
 this.facility = errorCode >>> 16 & 0x07ff;
 // bits 15 .. 0
 this.code = errorCode & 0xffff;

Quote:
}

// test sample (to be used in a try / catch stmt)
var ec = new ErrorCode(0x80040e14);
writeln('error    = ' + ec.error);
writeln('severity = ' + ec.severity);
writeln('facility = ' + ec.facility);
writeln('code     = ' + ec.code);

Eberhard



Quote:
> Check the types of the things you're testing.  With the implicit type
> conversions that are going on, sometimes you're comparing a string with a
> number, etc.



> > I know this sounds crazy but when I compare a variable with a value in
it
> to
> > the value in hex form (0x...) the comparison fails even though I know
that
> > this comparison is true.  When I compare it to the same value in decimal
> > form, the comparison succeeds.  What the hell?  Is there something wrong
> > with the current version of JScript that I can fix by getting a patch or
> > something?
> > please respond to the address as I do not check newsgroups often.
> > any help appreciated,
> > brian




Sun, 02 Dec 2001 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. define a measurement doesn't seem to work

2. location.replace doesn't seem to work

3. response.expires doesn't seem to work!

4. My Script...Doesn't Seem to Work

5. CDONTS.DLL doesn't seem to work.

6. STMAdmin.dll to query NT Log doesn't seem to work properly

7. focus() doesn't seem to work in IE-6

8. change hex value to decimal

9. GS 3.51 on PC doesn't seem to find fonts

10. Why LoadPicture() works on local pathes and doesn't work on the URLS

11. works / doesn't work, why?

12. 'history' command doesn't work

 

 
Powered by phpBB® Forum Software