[转帖]MySQL: Convert decimal to binary
Author: User
Conversion from MySQL code Note: decimal. c
Bytes ------------------------------------------------------------------------------------------------------------
*
Convert decimal to its binary fixed-length Representation
Two representations of the same length can be compared with memcmp
With the correct-1/0/+ 1 Result
Synopsis
Decimal2bin ()
From-value to convert
To-points to buffer Where string representation shoshould be stored
Precision/scale-see decimal_bin_size () below
Note
The buffer is assumed to be of the size decimal_bin_size (precision, scale)
Return Value
E_dec_ OK/e_dec_truncated/e_dec_overflow
Description
For storage decimal numbers are converted to the "binary" format.
This format has the following properties:
1. Length of the binary representation depends on the {precision, scale}
As provided by the caller and not on the intg/frac of the decimal
Convert.
2. Binary representations of the same {precision, scale} can be compared
With memcmp-with the same result as decimal_cmp () of the original
Decimals (not taking into account possible precision loss
Conversion ).
This binary format is as follows:
1. First the number is converted to have a requested precision and scale.
2. Every full dig_per_dec1 digits of intg part are stored in 4 bytes
As is
3. The first intg % dig_per_dec1 digits are stored in the specified CED
Number of bytes (enough bytes to store this number of digits-
See dig2bytes)
4. Same for frac-full decimal_digit_t's are stored as is,
The last frac % dig_per_dec1 digits-in the specified ced number of bytes.
5. If the number is negative-every byte is inversed.
5. The very first bit of the resulting byte array is inverted (because
Memcmp compares unsigned bytes, see property 2 above)
Example:
1234567890.1234
Internally is represented as 3 decimal_digit_t's
1 234567890 123400000
(Assuming we want a binary representation with precision = 14, scale = 4)
In hex it's
00-00-00-01 0d-fb-38-d2 07-5a-ef-40
Now, middle decimal_digit_t is full-It stores 9 decimal digits. It goes
Into binary representation as is:
...... 0d-fb-38-d2 ............
First decimal_digit_t has only one decimal digit. We can store one digit in
One byte, no need to waste four:
01 0d-fb-38-d2 ............
Now, last digit. It's 123400000. We can store 1234 in two bytes:
01 0d-fb-38-d2 04-d2
So, we 've packed 12 bytes number in 7 bytes.
And now we invert the highest bit to get the final result:
81 0d FB 38 D2 04 D2
And for-1234567890.1234 it wocould be
7E F2 04 37 2D FB 2D
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
[转帖]MySQL: Convert decimal to binary的更多相关文章
- convert decimal to binary
public class Solution { public static void main(String[] args) { ; String str = ""; ) { ; ...
- convert decimal to binary using inbuilt function
package testpacknm; import java.util.Scanner; public class testcnm { public static void main(String[ ...
- Write a program to convert decimal to 32-bit unsigned binary.
Write a program to convert decimal to 32-bit unsigned binary. Write a program to convert a 32-bit un ...
- MySQL中 DECIMAL FLOAT DOUBLE的区别
第一篇文章: MySQL中Decimal类型和Float Double等区别 MySQL中存在float,double等非标准数据类型,也有decimal这种标准数据类型. 其区别在于,float,d ...
- mysql 由decimal 引起的 Warning: Data truncated for column
今天在使用python 库mysqldb的rawsql的时候遇到一个问题(其实并不是mysqlbean引起的) cls.raw_sql('update {table} set available_am ...
- [Algorithm] Convert a number from decimal to binary
125, how to conver to binary number? function DecimalToDinary (n) { let temp = n; let list = []; if ...
- MySQL中Decimal类型和Float Double的区别 & BigDecimal与Double使用场景
MySQL中存在float,double等非标准数据类型,也有decimal这种标准数据类型. 其区别在于,float,double等非标准类型,在DB中保存的是近似值,而Decimal则以字符串的形 ...
- MySQL数据类型-decimal详解
from:http://www.linuxidc.com/Linux/2013-07/88032.htm 1.首先,对于精度比较高的东西,比如money,我会用decimal类型,不会考虑float, ...
- Convert a given Binary Tree to Doubly Linked List
The question and solution are from: http://www.geeksforgeeks.org/convert-given-binary-tree-doubly-li ...
- Convert string to binary and binary to string in C#
String to binary method: public static string StringToBinary(string data) { StringBuilder sb = new S ...
随机推荐
- Pikachu漏洞靶场 URL重定向
URL重定向 点击 我就是我,放荡不羁的我 可以发现url是这样的: http://192.168.171.30/pikachu/vul/urlredirect/urlredirect.php?url ...
- Docker安装 配置
Docker的技术原理: 1. Linux 命名空间(Namespaces) 进程命名空间:使得每个容器拥有独立的进程空间,互相隔离,不受其他容器影响. 网络命名空间:提供独立的网络栈,每个容器有自己 ...
- ClickHouse的JOIN算法选择逻辑以及auto选项
ClickHouse的JOIN算法选择逻辑以及auto选项 ClickHouse中的JOIN的算法有6种: Direct; Partial merge; Hash; Grace hash; Full ...
- Java 8升级Java 11,升级必知要点!竟然有这些坑…
随着技术的不断进步,Java作为一种广泛使用的编程语言,其版本更新带来了许多新特性和性能提升.从Java 8升级到Java 11,是一个重要的转变,它不仅带来了新的编程范式,还引入了对现代软件开发的多 ...
- 中国汽车工业协会 SDV 软件定义汽车服务 API 第三版下载
开门见山,下载链接: https://files.cnblogs.com/files/tengzijian/SDV_API_Version3_Beta1_公众号:好记性如烂笔头.zip?t=16904 ...
- 拖拽功能实现vue
1.按钮 <el-button @mousedown="down" @touchstart="down" @mousemove="move&qu ...
- MongoDB经典故障系列六:CPU利用率太高怎么办?
每逢电商大促,全民狂欢,但热闹是属于疯狂剁手的人们.而开发者们有的缺是"高流量.高访问.高并发"三高下带来的种种问题.为了应对大促期间的高I/O情况,企业会选择MongoDB云数据 ...
- Java注解(批注)的基本原理
为什么要使用注解? 早期版本的Spring是通过XML文件的形式对整个框架进行配置的,一个缩减版的配置文件如下 <?xml version="1.0" encoding=&q ...
- ByteHouse技术白皮书正式发布,云数仓核心技术能力首次全面解读(内附下载链接)
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 近日,<火山引擎云原生数据仓库 ByteHouse 技术白皮书>正式发布. 在数字化浪潮下,伴随着公有 ...
- Vue框架基础
博客目录 前端发展介绍 Vue的快速使用 插值语法 指令系统之文本指令.事件指令.属性指令 style和class 条件渲染 列表渲染 使用v-for进行循环 监控失效 双向数据绑定 input输入框 ...