mysql 16位 服务器 int,MySQL vs SQL Express服务器(十六进制-> bigint和bigint->十六进制转换)...

I am new to the SQL express server and trying to convert HEX to bigint and bigint to HEX again. However, I noticed that MySQL and SQL express server calculations give different results.

HEX to bigint:

MySQL:

SELECT CONV('DA346CC793AD1510',16,10);

Output:

15723311803489129744

SQL Express :

SELECT CAST(CONVERT(VARBINARY(MAX), 'DA346CC793AD1510', 2) AS BIGINT);

Output:

-2723432270220421872

Why MySQL and SQL express servers give different outputs? From a mathematical point of view, it must be the same.

However, bigint to HEX conversion in both MySQL and the SQL express servers give the same result.

MySQL: select conv(column_name,10,16);

SQL Express select FORMAT(column_name,'X');

What is the right way in the SQL express server to convert HEX to bigint and bigint to HEX? Am I missing something?

解决方案"Why MySQL and SQL express servers give different outputs? From a mathematical point of view, it must be the same."

BIGINT upper range is 2 to power 63 - 1:

9,223,372,036,854,775,807 -- upper range of BIGINT

15,723,311,803,489,129,744 -- converted "DA346CC793AD1510" value

BIGINT cannot store such value and simply overflows:

9,223,372,036,854,775,807 -> (overflow) -> starting from the lowest value (-9,223,372,036,854,775,808) + (15,723,311,803,489,129,744 - 9,223,372,036,854,775,807) -> -2,723,432,270,220,421,872

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值