如何在HEXTORAW()函数的工作?是什么算法? [英] How does the HEXTORAW() function work? What is the algorithm?

查看:1083
本文介绍了如何在HEXTORAW()函数的工作?是什么算法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HEXTORAW有几种RDBMS的如甲骨文和<一href="http://www-01.ibm.com/support/knowledgecenter/SSEPGG_10.5.0/com.ibm.db2.luw.sql.ref.doc/doc/r0059480.html"相对=nofollow> DB2 LUW上。它需要一个字符或整数输入,并基本上它强制转换为十六进制值。

HEXTORAW is a function found in several RDBMS's like Oracle, and DB2 on LUW. It takes a character, or integer input, and basically casts it to a HEX value.

HEXTORAW(1234) = x'1234'

什么是算法,这种类型的转换?什么是发生在幕后的code?

What is the algorithm for this type conversion? What is happening in the code behind the scenes?

(这是由希望创建在不具有所述功能HEXTORAW一个RDBMS此功能的动机。)

(This is motivated by wanting to create this function in an RDBMS that does not have the HEXTORAW function.)

推荐答案

为了有一个完整的算法在这里:

In order to have a complete algorithm here:

给定的字符串作为输入参数

Given a character string as an input parameter

1.Validate该字符串只包含数字1-9或字母AF。

1.Validate that the character string contains only the numbers 1-9 or the letters A-F.

2.Calculate通过遍历每个字符的二进制值, 和连接对应的二进制值:

2.Calculate the binary value by iterating over each character, and concatenating the corresponding binary value:

 binary    hexadecimal
 0000      0
 0001      1
 0010      2
 0011      3
 0100      4
 0101      5
 0110      6
 0111      7
 1000      8
 1001      9
 1010      a  
 1011      b
 1100      c  
 1101      d  
 1110      e  
 1111      f  

例如, 1234 的是:

0001 0010 0011 0100

3,采用该值,设定一个存储单元的位。

3.Using that value, set the bits of a memory location.

4.Address它作为一种原始数据类型

4.Address it as a raw datatype

5.Return它作为函数的返回值

5.Return it as the function return value

将得到的原始数据类型将有六角重新$ P相当于原来的字符串$ psentation。

The resulting raw datatype will have the hex representation equivalent to the original string.

鉴于输入'1234'该函数将返回的原始数据类型这将被显示为十六进制值x'1234'。二进制数据通常被重新psented十六进制,使其更易于阅读和参考$ P $。

Given the input '1234' the function would return the raw datatype which would be displayed as the hex value x'1234'. Binary data is typically represented in HEX to make it easier to read and reference.

(此基础上马克J. Bobak的答案,所以我想给贷款给他,但我也想发布一个完整的过程。)

(This builds on Mark J. Bobak's answer, so I want to give credit to him, but I also wanted to post a complete procedure.)

这篇关于如何在HEXTORAW()函数的工作?是什么算法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆