[转帖]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 ...
随机推荐
- Java 集合(三)ConcurrentHashMap
一般来讲,通常使用的 HashMap 不是线程安全的,因为没有任何机制来保证每个操作的原子性.在 ConcurrentHashMap 出现之前,可以通过给 HashMap 的每个操作加上唯一的互斥锁来 ...
- 1、Flutter把内容单独抽离成一个组件
//代码块 importM import 'package:flutter/material.dart'; void main() { runApp( MaterialApp( theme ...
- Python中的@abstractmethod
@abstractmethod 是 Python 中 abc 模块(Abstract Base Classes)提供的一个装饰器,用于声明抽象方法.抽象方法是指在抽象类中声明但没有提供具体实现的方 ...
- react路由权限v6
方法 1.模拟vue的路由拦截(未尝试) 2.进入页面拦截(模拟后台管理系统) route v6常用属性 页面梳理 路由表 公共路由 权限路由 layout(+权限判定) 登录 页面布局 路由表 点击 ...
- Java 插入Excel页眉、页脚
前言 在Excel文档中,我们常用页眉页脚来显示文档的附加信息,例如日期.公司名称.Logo或作者信息等.本文将通过Java程序来介绍如何给Excel文档添加页眉页脚.代码示例主要从以下几方面来演示添 ...
- 【文末彩蛋】数据仓库服务 GaussDB(DWS)单点性能案例集锦
摘要:介绍了13种GaussDB(DWS)单点性能的案例. 一.数据倾斜 1.1 问题描述 某局点SQL执行慢,涉及大表的SQL执行不出来结果. 1.2 分析过程 数据倾斜在很多方面都会有体现: 1) ...
- CANN 6.0来了,硬核技术抢先看
摘要:在华为全联接大会2022期间,华为正式官宣昇腾AI异构计算架构CANN 6.0版本将在年底正式发布. 本文分享自华为云社区<昇腾AI异构计算架构CANN 6.0全新开放升级,全面释放AI生 ...
- KubeEdge边缘计算在顺丰科技工业物联网中的实践
摘要:顺丰物联网平台负责人胡典钢为大家带来了 " 边缘计算在工业物联网中的应用实践与思考 " ,阐述了工业物联网的发展背景.整体架构设计以及边缘计算在此过程中承担的重要角色,并梳理 ...
- 7000+字图文并茂解带你深入理解java锁升级的每个细节
摘要:对于java锁升级,很多人都停留在比较浅层的表面理解,这篇7000+字和图解带你深入理解锁升级的每个细节. 本文分享自华为云社区<对java锁升级,你是否还停留在表面的理解?7000+字和 ...
- centos8 测地卸载php5.6 与卸载php7
centos8 yum php 默认安装 php7.1.2 我想卸载php7 ,安装php5.6 yum remove php 无法彻底卸载干净.必须强制删除,使用下面命令查看全部php软件包 rpm ...