Jump to content

BinaryToString cant convert 0xB4 to utf8


Invicore
 Share

Recommended Posts

Hi I dont know why, but BinaryToString cant convert 0xB4 to string in utf8 mode

I mean when I use this code to convert 0xB4 to utf8 it cant and just give me �

ConsoleWrite(BinaryToString("0xB4",4) & @CRLF)

but when I convert it to ascii, its convert it without any problem

ConsoleWrite(BinaryToString("0xB4",1) & @CRLF)

and give me " ´ "

can anyone help me and tell what I'm doing wrong? thanks

Edited by Invicore
Link to comment
Share on other sites

Link to comment
Share on other sites

Just now, matwachich said:

Dont forget to set SciTE's console to display UTF8 chars.

its just for showing my problem, in full code converted string save into a txt file (utf8-bom)

Just now, Nine said:

0xB4 has its MSB set to 1.  So it requires at least a second byte.

That char in UTF-8 is 0xC2B4

thank you, I understand, look like my only option is to only convert it as ascii, or maybe its possible to find this kind of character when using BinaryToString? 

can you please tell me how many character are looks like this (I mean ascii code is different then utf8), maybe I can put some exception, like

$S = ""
$Str = ""
Do
    $Str &= $S
    $S = FileRead($File, 1)
    If $S == 0xB4 then $S = 0xC2B4
Until $S = 0

btw I use above code to read null-terminated strings

Edited by Invicore
Link to comment
Share on other sites

13 minutes ago, Invicore said:

can you please tell me how many character are looks like this

As table shows above, from 0x80 to 0xFF.

Here a way to convert properly a char :

#include <Constants.au3>

Local $cASCII = Chr(0xB4)
Local $iUTF8 = StringToBinary($cASCII, 4)
Local $cUTF8 = BinaryToString($iUTF8, 4)

MsgBox ($MB_SYSTEMMODAL, $iUTF8, "is char " & $cUTF8 & @CRLF)

 

Edited by Nine
Link to comment
Share on other sites

You can convert a whole file (single ASCII string) like this :

#include <Constants.au3>

Local $sASCII = ""
For $i = 0x70 To 0x90 ; for an example instead of reading an ASCII file
  $sASCII &= Chr($i)
Next

Local $dUTF8 = StringToBinary($sASCII, 4)
ConsoleWrite ($dUTF8 & @CRLF)
Local $sUTF8 = BinaryToString($dUTF8, 4)
MsgBox ($MB_SYSTEMMODAL, "Converted", $sUTF8)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...