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 8150403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:03:28+00:00 2026-06-06T15:03:28+00:00

I want to Bitwise-XOR a string (actually its binary representation) with a KEY. The

  • 0

I want to Bitwise-XOR a string (actually its binary representation) with a KEY.

The result of the operation should be represented as HEX.

What I have:
‘a’ – the UTF-8 String to be changed.
‘ACF123456’ – the key in HEX.

Result seen as BIGINT:

select CONV(HEX('a'), 16, 10)  ^  CONV('ACF123456', 16, 10);

Result seen as HEX:

select CONV( CONV(HEX('a'), 16, 10)  ^  CONV('ACF123456', 16, 10), 10, 16);

Questions:

  1. Is the conversion above done correctly?
  2. What happens if the string is too long (i.e instead of ‘a’ we have ‘a veeeeeery long string’)? It seems that the conv() function has a limitation (is it the 64-bit precision from the documentation)? And besides the XOR operator ^ has also a limitation, related to the nr. of bits of the returned result. Any solutions that work for any string (a stored procedure is allowed)?

Thanks.

  • 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-06T15:03:30+00:00Added an answer on June 6, 2026 at 3:03 pm

    Your conversions look fine to me.
    And as you point out, both CONV() and ^ have indeed a 64-bits precision.

    2^64 = 16^16, therefore strings of more than 16 hexadecimal digits should convert to integers larger than 2^64. However, such strings will be brutally (silently) truncated from the left when attempting to convert them to integers.

    The point of my solution here is to slice such strings. Obviously, the result may not be displayed as an integer, but only as a string representation.

    Let @input be your “string to be changed” and @key, your “key”.

    1. Assign HEX(@input) to @hex_input. No problem here since HEX() works with strings.
    2. Slice @hex_input into 16 hexadecimal digit long strings, starting from the right
    3. Likewise, slice @key into 16 digit long strings.
    4. Compute the X-OR of each 64-bit slice of @hex_input with each 64-bit slice of @key, starting from the right. Use CONV(@slice, 16, 10). If either @hex_input or @key has less slices than the other string, then X-OR the remaining slices of the other string with 0.
    5. Convert each 64-bit number resulting from the X-OR in point 4. back into an hexadecimal string with UNHEX().
    6. Reassemble the resulting slices. This is your result.

    A three-columns TEMPORARY table could be used as an array to store slices of @hex_input, @mask and the resulting slices.

    Put this all together into a stored procedure, and voilà!

    You sound like you have some skills in MySQL, you should be able to translate the above into real code. But I’ll be happy to help if you need further guidance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to store the binary value of each character in a string and
I have two 8bpp bitmaps. I want to do a bitwise AND of one
I want to perform a bitwise-AND operation in VB.NET, taking a Short (16-bit) variable
I have two char 's and I want to stitch them bitwise together. For
want to know why String behaves like value type while using ==. String s1
want to have a Hyperlink-Button in a gridView in which I can display a
Want to code a key pad for an calculator. What I want to make
If I have a 32 bit two's complement number and I want to know
Original question changed. I want to bitwise turn off the left most bit of
I am pretty new to bitwise operators. Let's say I have 3 variables a

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.