Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2003
    Posts
    44

    Unanswered: 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

  2. #2
    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

  3. #3
    Join Date
    May 2003
    Location
    USA
    Posts
    5,737
    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

  4. #4
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    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.

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •