I cam across a situation where, I have to write a java
code for the teradata function called To_Bytes
. I have to write the function which will works exactly same as To_Bytes
in tera data.
From teradata doc.
To_Bytes
Decodes a sequence of characters in a given encoding into a sequence of bits. The following encodings are supported:
- BaseX • BaseY • Base64M (MIME) • ASCII
where X is a power of 2 (for example, 2, 8, 16) and Y is not a power of 2 (for example, 10 and 36).
Example_1,
SELECT TO_BYTES ('5A', 'base16');
returns '01011010'
Example_2,
SELECT TO_BYTES ('-22EEVX', 'base36');
returns '111 1000 1000 1101 0011 0011 0010 0011'
If anyone of you has any idea how to do that, please share , appreciate a lot.
1 Answers
Answers 1
You can start with smth like (not a complete solution, just a kick in the possible direction):
String s = "ROGER"; byte[] bytes = s.getBytes(); for (int i=0;i<bytes.length;i++) { System.out.println(Integer.toBinaryString(0x100 + bytes[i]).substring(1)); }
0 comments:
Post a Comment