Utf8
De Linuxmemo.
Sommaire |
[modifier] Code dans Vim
For instance, in the vim text-editor you would enter insert mode and press CTRL+VU and then the code-point number as a 4-digit hexadecimal number (pad with zeros if necessary). So you would type
CTRL+V. U 2 6 2 0.
[modifier] Code dans le Shell
At a terminal running Bash you would type CTRL+SHIFT+U and type in the hexadecimal code-point of the character you want. During input your cursor should show an underlined u. The first non-digit you type ends input, and renders the character. So you could be able to print U+2620 in Bash using the following:
echo CTRL+SHIFT+U2620ENTERENTER
(The first enter ends Unicode input, the second runs the echo command)
[modifier] Code avec echo
In UTF-8 it's actually 6 digit (or 3 byte).
$ echo -e "\xE2\x98\xA0" ☠
To check how it's encoded by you console, you can use hexdump. echo -n ☠ | hexdump
[modifier] Code avec printf
- via printf
printf '\xc3\xa0'
- via le shell :
printf $'\xc3\xa0'
- idem en ksh (88/93) :
typeset -i8 a=16#c3 b=16#a0 print “\${a#8\#}\${b#8\#}”
[modifier] Table Utf8
[modifier] Utile
- Embedded
Raw ASCII text with UTF-8 encoded characters represented by backslash escapes:
Hexadecimal: \x12 \x34 \x56 \x78 Decimal: \d123 \d45 \d67 Octal: \123 \45 Binary: \b01010101 \b10101010 \b11110000
- Freeform numeric
Space separated bytes in one or more of the following numeric forms:
Hexadecimal: 0x12 0x34 0x56 0x78 or x12 x34 x56 x78 Decimal: 123 45 67 Octal, using either backslashes or leading 0s: \123 \45 or 0123 045 Binary: 0b01010101 0b10101010 0b11110000
- UTF représentation
\uNNNN pour les codes en utf8 (code hexa en 4 caractères)
- retour chariot est le charactère "\u240D"
- tabulation est \x09 ou \u0009
- \x0d\x0a
\x0A is the escaped hexadecimal Line Feed. The equivalent of \n. \x0D is the escaped hexadecimal Carriage Return. The equivalent of \r.
[modifier] Conversion depuis le sheel
- Decimal to Hexadecimal
echo 'obase=16;10'| bc A
Ou
wcalc -h 10
- Decimal to Octal
echo 'obase=8;10' | bc 12
Ou
wcalc -o 10
- Decimal to Binary
echo 'obase=2;10' | bc 1010
Ou
wcalc -b 10
- From Hexadecimal to decimal
echo 'ibase=16;A' | bc 10
- From Octal to Decimal
echo 'ibase=8;12 | bc 10
- From Binary to Decimal
echo 'ibase=2;1010 | bc 10