If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > Hex to Base64 conversion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-02-06, 11:17
ek1975 ek1975 is offline
Registered User
 
Join Date: Sep 2003
Posts: 44
Hex to Base64 conversion

Platform: z/OS; Database: DB2 for z/OS v7.2

Hello, I got a field declared as "VARCHAR(20480) FOR BIT DATA" which holds images. I need to send these images to clients in XML format & I need to convert this binary data (DB2 has them already in Base16) to Base64 before I can embed them in XML.

Any suggestions.... please? I guess if there is no in-built convertion facilities on Cobol or DB2 for the mainframe, I will have to write my own (God help me!).

thanks in advance
Reply With Quote
  #2 (permalink)  
Old 03-02-06, 14:54
dbamota dbamota is offline
Registered User
 
Join Date: Sep 2003
Posts: 237
If the number is already in binary, grouping them 4 at a time is base 16, grouping them 6 at a time is base 64, grouping them n at a time is base 2 to the power n. In cobol, by redefining the same work area 4 bits at a time and 6 bits at a time should do the trick. If you can give an example, that would help.
__________________
mota
Reply With Quote
  #3 (permalink)  
Old 03-02-06, 15:27
Marcus_A Marcus_A is offline
Registered User
 
Join Date: May 2003
Location: USA
Posts: 5,196
Quote:
Originally Posted by ek1975
Platform: z/OS; Database: DB2 for z/OS v7.2

Hello, I got a field declared as "VARCHAR(20480) FOR BIT DATA" which holds images. I need to send these images to clients in XML format & I need to convert this binary data (DB2 has them already in Base16) to Base64 before I can embed them in XML.

Any suggestions.... please? I guess if there is no in-built convertion facilities on Cobol or DB2 for the mainframe, I will have to write my own (God help me!).

thanks in advance
Why do you need base64? 64-bit computers still use hexidecimal when they store data to the best of my knowledge . I have never heard of a base64 character set.
__________________
M. A. Feldman
IBM Certified DBA on DB2 for Linux, UNIX, and Windows
IBM Certified DBA on DB2 for z/OS and OS/390
Reply With Quote
  #4 (permalink)  
Old 03-03-06, 09:33
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Quote:
Originally Posted by Marcus_A
Why do you need base64? 64-bit computers still use hexidecimal when they store data to the best of my knowledge . I have never heard of a base64 character set.
It's not a character set. It's a way of representing arbitrary binary data using only printable ASCII characters; it's a common method of sending binary data via text-based communication channels, such as e-mail.
Reply With Quote
  #5 (permalink)  
Old 03-03-06, 11:01
ek1975 ek1975 is offline
Registered User
 
Join Date: Sep 2003
Posts: 44
Quote:
Originally Posted by dbamota
If the number is already in binary, grouping them 4 at a time is base 16, grouping them 6 at a time is base 64, grouping them n at a time is base 2 to the power n. In cobol, by redefining the same work area 4 bits at a time and 6 bits at a time should do the trick. If you can give an example, that would help.

I am sorry I got you confused with the word binary there. I don't exactly have the image in 0's and 1's. When I query DB2 using QMF, the image data I see is represented in Base16. What I am planning to do is:
1) Do a SELECT HEX(image)
2) Convert the X'' hex data to binary, 2 hex characters at a time
3) Group 3 binary bytes and split them into 4 groups of 6 each
4) Assign the base64 value for each 6-bit with needed 0's and paddings (=)
5) Get admitted for psychiatric treatment

If anyone of you have a solution to make the first 4 steps easy, so I can avoid step 5, let me know please. I will be extremely grateful... no kidding
Let me know if you see something wrong with the logic too.

Marcus_A: n_i is right, Base64 (A-Z, a-z, /, +) is not a character set representation like EBCDIC or ASCII, it's just a representation of data in a different notation like base 2, base10, base16...
If I send the data in Base16, a 400 byte image will go out as an 800 byte image X''. if I do it in Base64, converting 3 bytes to 4 bytes will only cause a 33% more increase in size
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On