[转帖]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 ...
随机推荐
- Ubuntu 下建立 eclipse 启动图标,解决ADT没有菜单栏问题(转载)
原文地址 怎么在这应用程序里边建立图标$sudo gedit /usr/share/applications/Eclipse.desktop输入以下代码 [Desktop Entry]Name=Ecl ...
- thymeleaf自定义标签
前言 使用thymeleaf自定义标签,环境:springboot 2.3.7 + thymeleaf 3.0.11(2021-01-14最新版) 由于使用shiro,我们需要与thymeleaf整合 ...
- Spring Batch 的基本使用
简介 A lightweight, comprehensive batch framework designed to enable the development of robust batch a ...
- CodeForces 1459C 数论 GCD
CodeForces 1459C 数论 GCD 原题链接 题意 首先给出n个数 之后给出m个数,每次问之前的n个数加上当前的这个数之后,总体的gcd是多少,也就是答案需要求出m个总体的gcd 思路 因 ...
- Provider 四种消费者
Provider.of Provider.of 方法是 Provider 库中最常用的获取共享数据的方法之一.它接收一个 BuildContext 对象和一个泛型类型参数 T,会查找 Widget 树 ...
- SAM适配下游任务的探究:SAM Adapter
本文分享自华为云社区<SAM适配下游任务的探究:SAM Adapter>,作者:Hint. 近期大模型的涌现给AI研究带来显著的发展,META的工作Segment Anything(SAM ...
- 华为云CodeArts Req需求管理工具,7大特性限时免费体验
摘要:一图了解什么是华为云CodeArts Req 本文分享自华为云社区<华为云CodeArts Req需求管理工具,7大特性限时免费体验>,作者:华为云PaaS服务小智. 一图了解什么是 ...
- 这8个JS 新功能,你应该去尝试一下
摘要:本文主要介绍几个已经进入stage4的提案,这几个提案有望在2022年逐步纳入标准. 本文分享自华为云社区<2022 年你应该尝试的 8个 JavaScript 新功能>,作者:前端 ...
- 应用火山引擎 DataTester“避坑”,抖音实现用 A/B 实验快速试错
更多技术交流.求职机会,欢迎关注字节跳动数据平台微信公众号,回复[1]进入官方交流群 A/B 测试产品可以说是企业科学决策的基础"设施",能够帮助企业快速迭代产品. 在字节跳动,每 ...
- SrpingBoot 集成 xxl-job 部署在 Docker 上碰到的坑
如果不指定 xxl.job.executor.ip,默认会用 Docker 的IP,注册到 xxl-job 里面,这时候无法回调 如果xxl.job.executor.ip.xxl.job.execu ...