all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Decode the octets with hexadecimal values.
@ 2023-05-20  6:55 Hongyi Zhao
  2023-05-20  7:04 ` Platon Pronko
  0 siblings, 1 reply; 10+ messages in thread
From: Hongyi Zhao @ 2023-05-20  6:55 UTC (permalink / raw)
  To: help-gnu-emacs

Hi here,

According to one of the comments here [1], I try to read the related
discussion here [2], but al.howardknight.net doesn't do any decoding
of the articles and I will see some non-human readable stuff, for
example:

the shell first will do the same and then tell the kernel by means=20
of the system service =E2=80=9Cdup2=E2=80=9D to copy the contents of the en=
try #1 to=20
the entry #2.=C2=A0 Now two entries in the process' file descriptor=20
table=C2=A0=E2=80=93 #1 and #2=C2=A0=E2=80=93 refer to the opened file =E2=
=80=9Coutput.txt=E2=80=9D.

So, I would like to know how to decode the octets with hexadecimal
values with the help of Emacs.

[1] https://groups.google.com/g/comp.unix.shell/c/xXqxHrIchqg
[2] http://al.howardknight.net/?ID=165151671300

Best,
Zhao
-- 
Assoc. Prof. Hongsheng Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Decode the octets with hexadecimal values.
  2023-05-20  6:55 Decode the octets with hexadecimal values Hongyi Zhao
@ 2023-05-20  7:04 ` Platon Pronko
  2023-05-20  7:37   ` Hongyi Zhao
  0 siblings, 1 reply; 10+ messages in thread
From: Platon Pronko @ 2023-05-20  7:04 UTC (permalink / raw)
  To: Hongyi Zhao, help-gnu-emacs

On 2023-05-20 14:55, Hongyi Zhao wrote:
> Hi here,
> 
> According to one of the comments here [1], I try to read the related
> discussion here [2], but al.howardknight.net doesn't do any decoding
> of the articles and I will see some non-human readable stuff, for
> example:
> 
> the shell first will do the same and then tell the kernel by means=20
> of the system service =E2=80=9Cdup2=E2=80=9D to copy the contents of the en=
> try #1 to=20
> the entry #2.=C2=A0 Now two entries in the process' file descriptor=20
> table=C2=A0=E2=80=93 #1 and #2=C2=A0=E2=80=93 refer to the opened file =E2=
> =80=9Coutput.txt=E2=80=9D.
> 
> So, I would like to know how to decode the octets with hexadecimal
> values with the help of Emacs.
> 
> [1] https://groups.google.com/g/comp.unix.shell/c/xXqxHrIchqg
> [2] http://al.howardknight.net/?ID=165151671300
> 
> Best,
> Zhao

Hi!

That looks like quoted-printable encoding. I don't know how to decode that in Emacs,
but here's an example of how you can do that in Python:

import codecs
s = """
the shell first will do the same and then tell the kernel by means=20
of the system service =E2=80=9Cdup2=E2=80=9D to copy the contents of the en=
try #1 to=20
the entry #2.=C2=A0 Now two entries in the process' file descriptor=20
table=C2=A0=E2=80=93 #1 and #2=C2=A0=E2=80=93 refer to the opened file =E2=
=80=9Coutput.txt=E2=80=9D.
"""
print(codecs.decode(s.encode("utf8"), "QUOTED-PRINTABLE").decode("utf8").strip())

-- 
Best regards,
Platon Pronko
PGP 2A62D77A7A2CB94E




^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Decode the octets with hexadecimal values.
  2023-05-20  7:04 ` Platon Pronko
@ 2023-05-20  7:37   ` Hongyi Zhao
  2023-05-20  8:18     ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Hongyi Zhao @ 2023-05-20  7:37 UTC (permalink / raw)
  To: Platon Pronko; +Cc: help-gnu-emacs

On Sat, May 20, 2023 at 3:04 PM Platon Pronko <platon7pronko@gmail.com> wrote:
>
> On 2023-05-20 14:55, Hongyi Zhao wrote:
> > Hi here,
> >
> > According to one of the comments here [1], I try to read the related
> > discussion here [2], but al.howardknight.net doesn't do any decoding
> > of the articles and I will see some non-human readable stuff, for
> > example:
> >
> > the shell first will do the same and then tell the kernel by means=20
> > of the system service =E2=80=9Cdup2=E2=80=9D to copy the contents of the en=
> > try #1 to=20
> > the entry #2.=C2=A0 Now two entries in the process' file descriptor=20
> > table=C2=A0=E2=80=93 #1 and #2=C2=A0=E2=80=93 refer to the opened file =E2=
> > =80=9Coutput.txt=E2=80=9D.
> >
> > So, I would like to know how to decode the octets with hexadecimal
> > values with the help of Emacs.
> >
> > [1] https://groups.google.com/g/comp.unix.shell/c/xXqxHrIchqg
> > [2] http://al.howardknight.net/?ID=165151671300
> >
> > Best,
> > Zhao
>
> Hi!
>
> That looks like quoted-printable encoding. I don't know how to decode that in Emacs,
> but here's an example of how you can do that in Python:
>
> import codecs
> s = """
> the shell first will do the same and then tell the kernel by means=20
> of the system service =E2=80=9Cdup2=E2=80=9D to copy the contents of the en=
> try #1 to=20
> the entry #2.=C2=A0 Now two entries in the process' file descriptor=20
> table=C2=A0=E2=80=93 #1 and #2=C2=A0=E2=80=93 refer to the opened file =E2=
> =80=9Coutput.txt=E2=80=9D.
> """
> print(codecs.decode(s.encode("utf8"), "QUOTED-PRINTABLE").decode("utf8").strip())

Yes. This works.

But Emacs is also extremely powerful, I expect someone here can give
an Emacs-based solution.

> --
> Best regards,
> Platon Pronko
> PGP 2A62D77A7A2CB94E

Regards,
Zhao



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Decode the octets with hexadecimal values.
  2023-05-20  7:37   ` Hongyi Zhao
@ 2023-05-20  8:18     ` Eli Zaretskii
  2023-05-20  8:51       ` Hongyi Zhao
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2023-05-20  8:18 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Hongyi Zhao <hongyi.zhao@gmail.com>
> Date: Sat, 20 May 2023 15:37:42 +0800
> Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
> 
> But Emacs is also extremely powerful, I expect someone here can give
> an Emacs-based solution.

We have quoted-printable-decode-region.



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Decode the octets with hexadecimal values.
  2023-05-20  8:18     ` Eli Zaretskii
@ 2023-05-20  8:51       ` Hongyi Zhao
  2023-05-20  9:44         ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Hongyi Zhao @ 2023-05-20  8:51 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 451 bytes --]

On Sat, May 20, 2023 at 4:18 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Hongyi Zhao <hongyi.zhao@gmail.com>
> > Date: Sat, 20 May 2023 15:37:42 +0800
> > Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
> >
> > But Emacs is also extremely powerful, I expect someone here can give
> > an Emacs-based solution.
>
> We have quoted-printable-decode-region.

But the result will be the one shown in the attached screenshot.

Best,
Zhao

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 176078 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Decode the octets with hexadecimal values.
  2023-05-20  8:51       ` Hongyi Zhao
@ 2023-05-20  9:44         ` Eli Zaretskii
  2023-05-20 10:53           ` Hongyi Zhao
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2023-05-20  9:44 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Hongyi Zhao <hongyi.zhao@gmail.com>
> Date: Sat, 20 May 2023 16:51:19 +0800
> Cc: help-gnu-emacs@gnu.org
> 
> On Sat, May 20, 2023 at 4:18 PM Eli Zaretskii <eliz@gnu.org> wrote:
> >
> > > From: Hongyi Zhao <hongyi.zhao@gmail.com>
> > > Date: Sat, 20 May 2023 15:37:42 +0800
> > > Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
> > >
> > > But Emacs is also extremely powerful, I expect someone here can give
> > > an Emacs-based solution.
> >
> > We have quoted-printable-decode-region.
> 
> But the result will be the one shown in the attached screenshot.

By default, the result is a unibyte string, you need to decode it to
get readable text:

  (quoted-printable-decode-region FROM TO 'utf-8)

(Do you read the doc strings of the functions before you use them?  If
not, you should: that's what they are there for.)



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Decode the octets with hexadecimal values.
  2023-05-20  9:44         ` Eli Zaretskii
@ 2023-05-20 10:53           ` Hongyi Zhao
  2023-05-20 11:01             ` Hongyi Zhao
  0 siblings, 1 reply; 10+ messages in thread
From: Hongyi Zhao @ 2023-05-20 10:53 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Sat, May 20, 2023 at 5:45 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Hongyi Zhao <hongyi.zhao@gmail.com>
> > Date: Sat, 20 May 2023 16:51:19 +0800
> > Cc: help-gnu-emacs@gnu.org
> >
> > On Sat, May 20, 2023 at 4:18 PM Eli Zaretskii <eliz@gnu.org> wrote:
> > >
> > > > From: Hongyi Zhao <hongyi.zhao@gmail.com>
> > > > Date: Sat, 20 May 2023 15:37:42 +0800
> > > > Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
> > > >
> > > > But Emacs is also extremely powerful, I expect someone here can give
> > > > an Emacs-based solution.
> > >
> > > We have quoted-printable-decode-region.
> >
> > But the result will be the one shown in the attached screenshot.
>
> By default, the result is a unibyte string, you need to decode it to
> get readable text:
>
>   (quoted-printable-decode-region FROM TO 'utf-8)
>
> (Do you read the doc strings of the functions before you use them?  If
> not, you should: that's what they are there for.)

Thank you for your valuable hints. The following steps do the trick:

1. C-x RET c utf-8-unix RET
2. Select/mark/highlight the text in question, and then
M-x quoted-printable-decode-region RET

Best,
Zhao



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Decode the octets with hexadecimal values.
  2023-05-20 10:53           ` Hongyi Zhao
@ 2023-05-20 11:01             ` Hongyi Zhao
  2023-05-20 12:37               ` Eli Zaretskii
  0 siblings, 1 reply; 10+ messages in thread
From: Hongyi Zhao @ 2023-05-20 11:01 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1518 bytes --]

On Sat, May 20, 2023 at 6:53 PM Hongyi Zhao <hongyi.zhao@gmail.com> wrote:
>
> On Sat, May 20, 2023 at 5:45 PM Eli Zaretskii <eliz@gnu.org> wrote:
> >
> > > From: Hongyi Zhao <hongyi.zhao@gmail.com>
> > > Date: Sat, 20 May 2023 16:51:19 +0800
> > > Cc: help-gnu-emacs@gnu.org
> > >
> > > On Sat, May 20, 2023 at 4:18 PM Eli Zaretskii <eliz@gnu.org> wrote:
> > > >
> > > > > From: Hongyi Zhao <hongyi.zhao@gmail.com>
> > > > > Date: Sat, 20 May 2023 15:37:42 +0800
> > > > > Cc: help-gnu-emacs <help-gnu-emacs@gnu.org>
> > > > >
> > > > > But Emacs is also extremely powerful, I expect someone here can give
> > > > > an Emacs-based solution.
> > > >
> > > > We have quoted-printable-decode-region.
> > >
> > > But the result will be the one shown in the attached screenshot.
> >
> > By default, the result is a unibyte string, you need to decode it to
> > get readable text:
> >
> >   (quoted-printable-decode-region FROM TO 'utf-8)
> >
> > (Do you read the doc strings of the functions before you use them?  If
> > not, you should: that's what they are there for.)
>
> Thank you for your valuable hints. The following steps do the trick:
>
> 1. C-x RET c utf-8-unix RET
> 2. Select/mark/highlight the text in question, and then
> M-x quoted-printable-decode-region RET

But by comparing the results of Python and Emacs, we can see that
there are three redundant underscores in the latter, as shown in the
attached screenshot. Any tips for this behavior?

> Best,
> Zhao

[-- Attachment #2: image.png --]
[-- Type: image/png, Size: 266292 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Decode the octets with hexadecimal values.
  2023-05-20 11:01             ` Hongyi Zhao
@ 2023-05-20 12:37               ` Eli Zaretskii
  2023-05-20 13:47                 ` Hongyi Zhao
  0 siblings, 1 reply; 10+ messages in thread
From: Eli Zaretskii @ 2023-05-20 12:37 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Hongyi Zhao <hongyi.zhao@gmail.com>
> Date: Sat, 20 May 2023 19:01:29 +0800
> Cc: help-gnu-emacs@gnu.org
> 
> But by comparing the results of Python and Emacs, we can see that
> there are three redundant underscores in the latter, as shown in the
> attached screenshot. Any tips for this behavior?

It's not an underscore, it's the NBSP character, I think?



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: Decode the octets with hexadecimal values.
  2023-05-20 12:37               ` Eli Zaretskii
@ 2023-05-20 13:47                 ` Hongyi Zhao
  0 siblings, 0 replies; 10+ messages in thread
From: Hongyi Zhao @ 2023-05-20 13:47 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: help-gnu-emacs

On Sat, May 20, 2023 at 8:37 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> > From: Hongyi Zhao <hongyi.zhao@gmail.com>
> > Date: Sat, 20 May 2023 19:01:29 +0800
> > Cc: help-gnu-emacs@gnu.org
> >
> > But by comparing the results of Python and Emacs, we can see that
> > there are three redundant underscores in the latter, as shown in the
> > attached screenshot. Any tips for this behavior?
>
> It's not an underscore, it's the NBSP character, I think?

Yes, you're right, as shown below:

M-x describe-char RET

             position: 152 of 260 (58%), column: 13
            character:   (displayed as  ) (codepoint 160, #o240, #xa0)
              charset: unicode (Unicode (ISO10646))
code point in charset: 0xA0
               script: latin
               syntax:       which means: whitespace
             category: .:Base, b:Arabic, j:Japanese, l:Latin
             to input: type "C-x 8 RET a0" or "C-x 8 RET NO-BREAK SPACE"
          buffer code: #xC2 #xA0
            file code: #xC2 #xA0 (encoded by coding system utf-8-unix)
              display: by this font (glyph code):
    ftcrhb:-PfEd-DejaVuSansMono Nerd Font
Mono-regular-normal-normal-*-20-*-*-*-m-0-iso10646-1 (#x62)
       hardcoded face: nobreak-space

Character code properties: customize what to show
  name: NO-BREAK SPACE
  old-name: NON-BREAKING SPACE
  general-category: Zs (Separator, Space)
  decomposition: (noBreak 32) (noBreak ' ')

There are text properties here:
  fontified            nil
  wrap-prefix          " "


Best,
Zhao



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-05-20 13:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-20  6:55 Decode the octets with hexadecimal values Hongyi Zhao
2023-05-20  7:04 ` Platon Pronko
2023-05-20  7:37   ` Hongyi Zhao
2023-05-20  8:18     ` Eli Zaretskii
2023-05-20  8:51       ` Hongyi Zhao
2023-05-20  9:44         ` Eli Zaretskii
2023-05-20 10:53           ` Hongyi Zhao
2023-05-20 11:01             ` Hongyi Zhao
2023-05-20 12:37               ` Eli Zaretskii
2023-05-20 13:47                 ` Hongyi Zhao

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.