# How to convert it into utf-8?

**URL:** <https://www.ruby-forum.com/t/how-to-convert-it-into-utf-8/191382>\
**Category:** Ruby\
**Created:** [July 11, 2010, 12:40pm UTC](https://www.ruby-forum.com/t/how-to-convert-it-into-utf-8/191382 "2010-07-11T12:40:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [July 11, 2010, 12:40pm UTC](https://www.ruby-forum.com/t/how-to-convert-it-into-utf-8/191382/1 "2010-07-11T12:40:43Z")

</div>

in my linux comsole:  
ghex2 /home/pt/myday  
there is the first line content  
AA3F3201861F0000D61F0000  
would you mind to tell me how can convert it into utf-8?

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [July 11, 2010, 6:03pm UTC](https://www.ruby-forum.com/t/how-to-convert-it-into-utf-8/191382/2 "2010-07-11T18:03:46Z")

</div>

On Sun, Jul 11, 2010 at 1:40 PM, Pen T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> in my linux comsole:  
> ghex2 /home/pt/myday  
> there is the first line content  
> AA3F3201861F0000D61F0000  
> would you mind to tell me how can convert it into utf-8?

I can’t tell which unicode range those specific code points belong to,  
but  
if you’re sure the hex data represents utf-8, and I understand what you  
are  
asking for correctly, try something like:

line.scan(/(…)/).each do |code\_point|  
puts code\_point.pack(‘H\*’)  
end

Depending on where the data is coming from, you might need to flip the  
bytes  
to account for endianness. I don’t believe that will be an issue on  
linux.

Hope it helps,  
Ammar

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [July 12, 2010, 1:47am UTC](https://www.ruby-forum.com/t/how-to-convert-it-into-utf-8/191382/3 "2010-07-12T01:47:49Z")

</div>

pt@pt-laptop:~$ file /home/pt/myday  
/home/pt/myday: data

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [July 12, 2010, 1:59am UTC](https://www.ruby-forum.com/t/how-to-convert-it-into-utf-8/191382/4 "2010-07-12T01:59:44Z")

</div>

would you mind to tell me your email? i can send the data file to  
you,please help me,think you in advance.

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [July 11, 2010, 10:58pm UTC](https://www.ruby-forum.com/t/how-to-convert-it-into-utf-8/191382/5 "2010-07-11T22:58:03Z")

</div>

Pen T. wrote:

> in my linux comsole:  
> ghex2 /home/pt/myday  
> there is the first line content  
> AA3F3201861F0000D61F0000  
> would you mind to tell me how can convert it into utf-8?

What do you meant “convert to utf-8”?

Those hex characters are very unlikely to be UTF-8. See

> **[UTF-8](https://en.wikipedia.org/wiki/UTF-8)**
>
> UTF-8 is a variable-length character encoding standard used for electronic communication. Defined by the Unicode Standard, the name is derived from Unicode (or Universal Coded Character Set) Transformation Format – 8-bit.
> UTF-8 is capable of encoding all 1,112,064\[a\] valid character code points in Unicode using one to four one-byte (8-bit) code units. Code points with lower numerical values, which tend to occur more frequently, are encoded using fewer bytes. It was designed for backward compati...

AA = second, third or fourth byte of multi-byte sequence  
3F = single-byte character (?)  
32 = single-byte character (2)  
01 = single-byte character (ctrl-A)  
86 = second, third or fourth byte of multi-byte sequence  
1F = single-byte character (ctrl-?)  
… etc

Apart from D6 there are no “start of n-byte sequence” characters

Try typing “file /home/pt/myday”, which will attempt to identify what  
sort of file you actually have.

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [July 12, 2010, 10:47am UTC](https://www.ruby-forum.com/t/how-to-convert-it-into-utf-8/191382/6 "2010-07-12T10:47:38Z")

</div>

Pen T. wrote:

> pt@pt-laptop:~$ file /home/pt/myday  
> /home/pt/myday: data

‘file’ knows many file formats - look at /usr/share/file/magic or  
/etc/magic depending on your system. But this isn’t one of them. Neither  
is the data UTF-8 text, or at least, the header isn’t.

You could look to see if there are any snippets of readable text in it:

```
strings /home/pt/myday | less

```

But if not, then it really is just binary data, and its meaning will  
depend on what program wrote it in the first place.
