Conversion between MySQL 10 binary and 35 binary note power handling bigint issues

Source: Internet
Author: User

35 binary is designed to prevent visual errors caused by 0 and O

BEGIN
DECLARE m_strhex35 VARCHAR (100); --Returns the result of the 35 binary representation
DECLARE M_remainder BIGINT; --Remainder
DECLARE m_base35 VARCHAR (1);

SET m_remainder=0;
SET m_strhex35= ";

While p_hex10>=35 do
SET m_remainder=p_hex10%35;
SET p_hex10= (P_hex10-m_remainder)/35;

SET m_base35=substring (' 0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ ', m_remainder+1,1);

SET M_strhex35=concat (m_base35,m_strhex35);

END while;

SET m_remainder=p_hex10%35;
SET m_base35=substring (' 0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ ', m_remainder+1,1);
SET M_strhex35=concat (m_base35,m_strhex35);
--PRINT @StrHex35
RETURN m_strhex35;
END

BEGIN
DECLARE M_strhex35len INT; --The length of the 35 binary string being converted
DECLARE M_base35to10 INT; --10 binary data size per bit of 35 binary cardinality
DECLARE M_index INT; --String index
DECLARE m_hex10 BIGINT; --is returned 10 binary data
DECLARE m_base35 VARCHAR (1); --35 binary cardinality

DECLARE M_middle_data BIGINT;

SET m_hex10=0;
SET m_strhex35len=length (p_strhex35);
SET m_index=1;

while (M_index<=m_strhex35len) do

SET m_base35=substr (p_strhex35 from M_index for 1);

SET m_base35to10= LOCATE (m_base35, ' 0123456789ABCDEFGHIJKLMNPQRSTUVWXYZ ')-1;

--NOTE: You must first save the value of power to a variable, and the result cannot be calculated directly by a different variable, which will result in incorrect calculation results
SET m_middle_data = POWER (35,m_strhex35len-m_index);

SET M_hex10=m_hex10+m_base35to10 * M_MIDDLE_DATA;

SET m_index=m_index+1;
END while;

RETURN m_hex10;
END

Conversion between MySQL 10 binary and 35 binary note power handling bigint issues

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.