将 0 和 1 的数组转换为 base36 字符串
事情是这样的。我有一个 0 和 1 的数组。它应该是一个二进制字符串。我需要的是将其格式化为包含该二进制文件的 base36 转换的字符串。 换句话说,我需要这样做: 1 和 0 的数组 ->某种二进制数 ->转换为base36数字->将其放入字符串中。 怎么做呢?
数千石油,300钢铁,回答者+1运气。
Here is the thing. I have an array of 0 and 1. It is supposed to be a binary string. What i need is to format it to string that contains base36 conversion from that binary.
In other words, i need to do this: array of 1 and 0 -> some kind of binary number -> convert to base36 number -> put it into string.
How to do that?
Thousands of oil, 300 steel and +1 luck to answerers.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没有内置的 Oracle 来执行此类转换。在下面的示例中,我使用了 不可估量的 Mr Kyte 编写的两个函数。
to_dec()
将其他基数转换为小数,to_base()
将小数转换为其他基数。该过程采用一个由 1 和 0 组成的数组,并返回一个以 36 为基数的字符串。
布丁的证明以及所有这些...
编辑
当我组装此示例时,您发布了您的零数组是~450 个条目长。这个例程不会处理这样的事情。在您命中该大小的数字之前,它会抛出
ORA-01426: numeric Overflow
。编辑2
如果您愿意冒险一点不精确,您可以将 NUMBER 变量替换为 BINARY_DOUBLE 变量(在我的示例和 Tom 的函数中)。该数据类型可以处理更大的数字。我将其提高到 array_count=470,在基数 36 中可能如下所示:
There is no Oracle built-in to do this sort of conversion. In the following example I use two functions witten by the inestimable Mr Kyte.
to_dec()
turns other bases to decimals, andto_base()
turns decimals into other bases.The procedure takes an array of ones and zeroes and returns a string of base 36.
The proof of the pudding and all that ...
edit
While I was assembling this sample you posted that your array of zeroes was ~450 entries long. This routine won't handle anything like that. It will hurl
ORA-01426: numeric overflow
way before you hit a number of that size.edit 2
If you are happy to gamble with a little imprecision, you could replace the NUMBER variables with BINARY_DOUBLE variables (in both my sample and Tom's functions). That datatype can handle much bigger numbers. I cranked it up to
array_count=470
, which might look like this in base 36 :