Microsoft KB Archive/272138

= PRB: Negative Integers Do Not Work as Unicode HTML Entity References =

Article ID: 272138

Article Last Modified on 5/11/2006

-

APPLIES TO


 * Microsoft Internet Explorer 4.0 128-Bit Edition
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 4.01 Service Pack 1
 * Microsoft Internet Explorer 4.01 Service Pack 2
 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer (Programming) 5.01 SP1
 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q272138



SYMPTOMS
Some functions, such as the Microsoft Visual Basic (VB) and Visual Basic Script (VBScript) AscW function, may return a negative number when you ask for the Unicode value of a non-Latin character (such as Chinese Hanzi, Japanese Kanji or Korean Hangul). When you use this negative number as an HTML entity reference (&#nnnn, where nnnn is either a hexadecimal or decimal Unicode number), you see the entity reference as literal text, instead of the corresponding non-Latin character.



CAUSE
Unicode numbers occupy a 16-bit positive range from 0 to 65535 (0xFFFF), and cannot be negative.



RESOLUTION
When AscW returns a negative number, it returns the twos complement form of that number. To convert the twos complement notation into normal binary notation, add 0xFFF to the return result. For an example, see the &quot;More Information&quot; section.



Steps to Reproduce Behavior
  Save the following HTML code to a file named TestAscW.htm: 

 PRB: Negative Integers Do Not Work as Unicode HTML Entity References 



// The character used below is the Japanese character &quot;go&quot; (8A9E in //Unicode).

sub load div1.innerHTML = &quot;Actual character is &#35486; & AscW output is &#&quot; & AscW(ChrW(35486)) end sub







</DIV>

</BODY>

</HTML> </li> <li>Open this file in Internet Explorer. The second character reference is displayed as raw text, and not as the Japanese character &quot;go.&quot;</li></ol>

To work around this problem, change the script block to the following: function DecodeAscW(sOutput) sAscVal = AscW(sOutput) If sAscVal < 0 Then sAscVal = 65536 + sAscVal End If   DecodeAscW = sAscVal end function

sub load div1.innerHTML = &quot;Actual character is &#35486; AscW output is &#&quot; & DecodeAscW(ChrW(35486)) end sub

<div class="references_section">