未验证 提交 032b8a8f 编写于 作者: A alexey-milovidov 提交者: GitHub

Update encoding_functions.md

上级 25fcf31a
......@@ -67,7 +67,7 @@ SELECT char(0xE4, 0xBD, 0xA0, 0xE5, 0xA5, 0xBD) AS hello;
## hex {#hex}
Возвращает строку, содержащую шестнадцатеричное представление аргумента.
Returns a string containing the argument's hexadecimal representation.
**Syntax**
......@@ -75,37 +75,51 @@ SELECT char(0xE4, 0xBD, 0xA0, 0xE5, 0xA5, 0xBD) AS hello;
hex(arg)
```
Результат зависит от типа передаваемого аргумента. Используйте заглавные буквы `A-F`. Не используйте префиксы `0x` и суффиксы `h`.
The function is using uppercase letters `A-F` and not using any prefixes (like `0x`) or suffixes (like `h`).
Для строк просто все байты кодируются в виде двух шестнадцатеричных цифр.
For integer arguments, it prints hex digits ("nibbles") from the most significant to least significant (big endian or "human readable" order). It starts with the most significant non-zero byte (leading zero bytes are omitted) but always prints both digits of every byte even if leading digit is zero.
Числа преобразуются в человекочитаемый (big endian) формат. Для чисел вырезаются старшие нули, но только по целым байтам.
Example:
Например:
**Example**
- `Date` кодируется как число дней с начала Unix-эпохи.
- `DateTime` кодируются как число секунд с начала Unix-эпохи.
- `Float` и `Decimal` кодируются как их шестнадцатеричное представление в памяти.
Query:
**Параметры**
```sql
SELECT hex(1);
```
- `arg` — Значение для преобразования в шестнадцатеричное. Типы: [String](../../data_types/string.md), [UInt](../../data_types/int_uint.md), [Float](../../data_types/float.md), [Decimal](../../data_types/decimal.md), [Date](../../data_types/date.md) or [DateTime](../../data_types/datetime.md).
Result:
**Влзвращаемое значение**
```text
01
```
- Строковое шестнадцатеричное представление переданного аргумента.
Values of type `Date` and `DateTime` are formatted as corresponding integers (the number of days since Epoch for Date and the value of Unix Timestamp for DateTime).
Тип: `String`.
For `String` and `FixedString`, all bytes are simply encoded as two hexadecimal numbers. Zero bytes are not omitted.
**Пример**
Values of floating point and Decimal types are encoded as their representation in memory. As we support little endian architecture, they are encoded in little endian. Zero leading/trailing bytes are not omitted.
Запрос:
**Parameters**
- `arg` — A value to convert to hexadecimal. Types: [String](../../data_types/string.md), [UInt](../../data_types/int_uint.md), [Float](../../data_types/float.md), [Decimal](../../data_types/decimal.md), [Date](../../data_types/date.md) or [DateTime](../../data_types/datetime.md).
**Returned value**
- A string with the hexadecimal representation of the argument.
Type: `String`.
**Example**
Query:
```sql
SELECT hex(toFloat32(number)) as hex_presentation FROM numbers(15, 2);
```
Ответ:
Result:
```text
┌─hex_presentation─┐
......@@ -114,13 +128,13 @@ SELECT hex(toFloat32(number)) as hex_presentation FROM numbers(15, 2);
└──────────────────┘
```
Запрос:
Query:
```sql
SELECT hex(toFloat64(number)) as hex_presentation FROM numbers(15, 2);
```
Ответ:
Result:
```text
┌─hex_presentation─┐
......@@ -130,8 +144,9 @@ SELECT hex(toFloat64(number)) as hex_presentation FROM numbers(15, 2);
```
## unhex(str)
Принимает строку, содержащую произвольное количество шестнадцатеричных цифр, и возвращает строку, содержащую соответствующие байты. Поддерживаются как строчные, так и заглавные буквы A-F. Число шестнадцатеричных цифр не обязано быть чётным. Если оно нечётное - последняя цифра интерпретируется как младшая половинка байта 00-0F. Если строка-аргумент содержит что-либо кроме шестнадцатеричных цифр, то будет возвращён какой-либо implementation-defined результат (не кидается исключение).
Если вы хотите преобразовать результат в число, то вы можете использовать функции reverse и reinterpretAsType.
Accepts a string containing any number of hexadecimal digits, and returns a string containing the corresponding bytes. Supports both uppercase and lowercase letters A-F. The number of hexadecimal digits does not have to be even. If it is odd, the last digit is interpreted as the least significant half of the 00-0F byte. If the argument string contains anything other than hexadecimal digits, some implementation-defined result is returned (an exception isn't thrown).
If you want to convert the result to a number, you can use the 'reverse' and 'reinterpretAsType' functions.
## UUIDStringToNum(str)
Принимает строку, содержащую 36 символов в формате `123e4567-e89b-12d3-a456-426655440000`, и возвращает в виде набора байт в FixedString(16).
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册