Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7771127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:34:21+00:00 2026-06-01T16:34:21+00:00

Using some various Stackoverflow sources I’ve implemented a fairly simple Base64 to Hex conversion

  • 0

Using some various Stackoverflow sources I’ve implemented a fairly simple Base64 to Hex conversion using JAVA. Due to a problem however I tested my results by attempting to convert my hex code back to text to confirm that it was correct and found that the character at index 11 (the left quote mark) is being lost in translation somehow.

Why does the hexToASCII convert everything except the left quote mark?

public static void main(String[] args){
     System.out.println("Input string:");
     String myString = "AAAAAQEAFxUX1iaTIz8=";
     System.out.println(myString + "\n");

     //toascii
     String ascii = base64UrlDecode(myString);
     System.out.println("Base64 to Ascii:\n" + ascii);

     //tohex
     String hex = toHex(ascii);
     System.out.println("Ascii to Hex:\n" + hex);
     String back2Ascii = hexToASCII(hex);
     System.out.println("Hex to Ascii:\n" + back2Ascii + "\n");
}

public static String hexToASCII(String hex){     
    if(hex.length()%2 != 0){
       System.err.println("requires EVEN number of chars");
       return null;
    }
    StringBuilder sb = new StringBuilder();               
    //Convert Hex 0232343536AB into two characters stream.
    for( int i=0; i < hex.length()-1; i+=2 ){
         /*
          * Grab the hex in pairs
          */
        String output = hex.substring(i, (i + 2));
        /*
         * Convert Hex to Decimal
         */
        int decimal = Integer.parseInt(output, 16);                 
        sb.append((char)decimal);             
    }           
    return sb.toString();
} 

  public static String toHex(String arg) {
    return String.format("%028x", new BigInteger(arg.getBytes(Charset.defaultCharset())));
  }

  public static String base64UrlDecode(String input) {
    Base64 decoder = new Base64();
    byte[] decodedBytes = decoder.decode(input);
    return new String(decodedBytes);
 }

Returns:

enter image description here

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:34:23+00:00Added an answer on June 1, 2026 at 4:34 pm

    It doesn’t loose it. It doesn’t understand in your default charset. Use arg.getBytes() instead, without specifying the charset.

    public static String toHex(String arg) {
       return String.format("%028x", new BigInteger(arg.getBytes()));
    }
    

    Also change hexToAscII method:

    public static String hexToASCII(String hex) {
        final BigInteger bigInteger = new BigInteger(hex, 16);
        return new String(bigInteger.toByteArray());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using some semi-transparent PNGs as background-images on various websites. These are usually something
I have created a few different full programming languages using some of the various
I have been using mplot3d (part of matplotlib) for some various 3d plotting, and
I'm using some code related to RTSP, RTP to listen to various RTSP Streams
Using some of the methods, I am able to check the orientations to which
Assuming I'm using some graphic API which allows me to draw bezier curves by
I am using some NHibernate 1.2 code with NHibernate 2.0 and its giving me
I am using some third party library to connect to a server via async
I'm using some code from here to determine when determining when the last finger
I am using some pre-written JavaScript from polldaddy. They have a JavaScript option which,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.