[转帖]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 ...
随机推荐
- 简易机器学习笔记(十一)opencv 简易使用-人脸识别、分类任务
前言 前段时间摸了下机器学习,然后我发现其实openCV还是一个很浩瀚的库的,现在也正在写一篇有关yolo的博客,不过感觉理论偏多,所以在学yolo之前先摸一下opencv,简单先写个项目感受感受op ...
- maven系列:POM文件总体配置说明
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- Go语言实现GoF设计模式:备忘录模式的实践探索
本文分享自华为云社区<[Go实现]实践GoF的23种设计模式:备忘录模式>,作者:元闰子. 简介 相对于代理模式.工厂模式等设计模式,备忘录模式(Memento)在我们日常开发中出镜率并不 ...
- 8种ETL算法汇总大全!看完你就全明白了
摘要:ETL是将业务系统的数据经过抽取.清洗转换之后加载到数据仓库的过程,是构建数据仓库的重要一环,用户从数据源抽取出所需的数据,经过数据清洗,最终按照预先定义好的数据仓库模型,将数据加载到数据仓库中 ...
- 数据湖探索DLI新功能:基于openLooKeng的交互式分析
摘要:基于华为开源openLooKeng引擎的交互式分析功能,将重磅发布便于用户构建轻量级流.批.交互式全场景数据湖. 在这个"信息爆炸"的时代,大数据已经成为这个时代的关键词之一 ...
- 如何通过一个SDK轻松搞定人脸识别,拯救初入职场的程序猿
摘要:看一个SDK如何拯救初入职场的程序猿小Hi- [职场初体验] 时间过得真快,距离上次给小Hi安排"人脸识别"的开发任务(话接上期:[快速玩转华为云开发]小Hi拍了拍你,基于华 ...
- CodeArts TestPlan:一站式测试管理平台
摘要:华为云正式发布CodeArts TestPlan,这是一款自主研发的一站式测试管理平台,沉淀了华为30多年高质量的软件测试工程方法与实践,覆盖测试计划.测试设计.测试执行和测试评估等全流程. 本 ...
- 带你认识图数据库性能和场景测试利器LDBC SNB
摘要:本文主要介绍基于交互式查询所用的数据生成器(下文简称Datagen),及LDBC SNB数据如何在华为图引擎服务GES中应用. 本文分享自华为云社区<[图数据库性能和场景测试利器LDBC ...
- 养殖场新来了个“AI管家”
摘要:定制化算法+端侧一键部署,打通AI全流程. 本文分享自华为云社区<[云享·伙伴]第4期:养殖场新来了个"AI管家">,作者: 华为云社区精选. 民以食为天.肉类是 ...
- 梳理数仓FI manager节点健康检查逻辑
摘要:一篇记录FI Manager节点健康检查机制的博文. 本文分享自华为云社区<GaussDB(DWS) FI manager节点健康检查逻辑梳理>,作者:配音师 . 一.相关背景 1. ...