[转帖]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 ...
随机推荐
- 斯坦福 UE4 C++ ActionRoguelike游戏实例教程 02.AI自定义任务和观察器中断
斯坦福课程 UE4 C++ ActionRoguelike游戏实例教程 0.绪论 概述 本文章对应课程第十一章 42节.这篇文章会进一步地为AI添加新功能,创建自定义任务,允许AI发射子弹,并且讲解观 ...
- 宝塔面板如何用一IP不同端口创建不同的网站(“您添加的站点已存在”)
问题描述 玩宝塔面板的时候,一开始没有云服务器,需要在本地虚拟机里搭建各种网站,想在本地服务器下搭建多个站点,但是总会遇到"您添加的站点已存在"这个现象. 问题原因及解决办法 出现 ...
- 6、Flutter 列表组件 滑动
列表有以下分类: 1.垂直列表 class MyApp extends StatelessWidget { const MyApp({super.key}); @override Widget bui ...
- 使用鼠标在图片上拖拽矩形框vue
<template> <div> <img class="no-drag" src="https://dashanbook.oss-cn-s ...
- FQS:一种神奇的数仓查询优化技术
本文分享自华为云社区<根据执行计划优化SQL[绽放吧!GaussDB(DWS)云原生数仓]>,作者:西岭雪山. 引言 如果您刚接触DWS那一定会好奇想要知道"REMOTE_FQS ...
- 解析Spring内置作用域及其在实践中的应用
摘要:本文详细解析了Spring的内置作用域,包括Singleton.Prototype.Request.Session.Application和WebSocket作用域,并通过实例讲解了它们在实际开 ...
- 知道Python中的字符串是什么吗?
摘要:本文将告诉您Python中的字符串是什么,并向您简要介绍有关该概念的所有知识. 本文将介绍以下内容: 如何创建一个字符串? 如何从字符串访问字符? 格式化字符串 因此,让我们开始吧. 什么是Py ...
- 4种Springboot RestTemplate 服务里发送HTTP请求用法
摘要: RestTemplate与REST资源交互的方法涵盖了HTTP请求方法,包括get, post, put, delete. 本文分享自华为云社区<Springboot RestTempl ...
- 协同文档:OT与CRDT实现协同编辑笔记
讲协同编辑,先回顾下从BBS.邮件,到IM 信息的异步传播 信息的生产和消费异步发生. 典型的场景如论坛,博客,文档库,邮件.我在写这篇文档的时候,你们看不到.你们看的时候,我早已写完.异步场景下,信 ...
- 【Redis】面试题 GEO地理位置信息
目录 面试 1 http协议详情,http协议版本,http一些请求头 2 GET请求和POST请求的区别 3 如何实现服务器给客户端发送消息,websocket是什么? 4 悲观锁和乐观锁,如何实现 ...