Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hex converter giving invalid results #15136

Closed
kartik1000 opened this issue Mar 31, 2019 · 8 comments · Fixed by #15779
Closed

Hex converter giving invalid results #15136

kartik1000 opened this issue Mar 31, 2019 · 8 comments · Fixed by #15779
Assignees
Labels
Bug A problem or regression with an existing feature has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete
Projects
Milestone

Comments

@kartik1000
Copy link
Contributor

Describe the bug

The hexadecimal converter 'HEX' in the insert field is giving invalid results. Suppose if I enter 70 as my int value it should give answer as '46' in HEX but it is giving answer as '3730'.
The 'OCT' converter for the same is working correct as I verified.

To Reproduce

  1. Add int type column in any table.
  2. Go to insert section.
  3. Select the function 'HEX' in that 'int' column.
  4. Enter some int value and observe the result in the added column

Expected behaviour

The 'HEX' function should give out the corrected value.

Screenshots

Screenshot 2019-03-31 at 10 47 55 PM
This value '3730' was received from type conversion of int '70' to hex

Server configuration

Operating system: macOS Server(5.7.1 )
Web server: Apache/2.4.37 (Unix) OpenSSL/1.0.2q PHP/7.3.0 mod_perl/2.0.8-dev Perl/v5.16.3
Database version: Localhost via UNIX socket
PHP version: 7.3.0
phpMyAdmin version: 4.8.4

Client configuration

Browser: Safari (12.0.3)
Operating system: macOS Mojave (version 10.14.2)

Additional context

Add any other context about the problem here.

@kartik1000
Copy link
Contributor Author

@williamdes, this was the one

@williamdes williamdes added Bug A problem or regression with an existing feature good first issue labels Mar 31, 2019
@apoorvkhare07
Copy link
Contributor

@williamdes I was looking into this issue and found that the issue is not with PMA code, rather this is a issue with mysql itself.

mysql give different output of HEX() when passed string('70') or int(70) whereas OCT() give same output for int and string.
Screen Shot 2019-04-02 at 4 26 12 PM

@kartik1000
Copy link
Contributor Author

Nice lead @apoorvkhare07👍. But shouldn't the input field take it as an int since my column type is int

apoorvkhare07 added a commit to apoorvkhare07/phpmyadmin that referenced this issue Apr 2, 2019
Signed-off-by: apoorv <apoorvkhare007@gmail.com>
@williamdes williamdes added the has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete label Apr 2, 2019
@williamdes williamdes added this to To be sorted in issues May 2, 2019
@williamdes williamdes moved this from To be sorted to Reproduced in issues May 4, 2019
@thesmallstar
Copy link
Contributor

thesmallstar commented Jan 11, 2020

@williamdes, I wanted to work on this.
The real issue is we cannot store a Hexadecimal number in an integer format if we convert an integer to hex it is quite possible it would have Alphabets that cannot be stored in an int.

But if we treat the integer as String we have a very special benefit.

Consider the number 4:

If we treat this as '4' instead it would be converted to hex in the following format:
HEX(ASCII(4)) = HEX(52) = 34

Similarly, the 'answer' for "44" is 3434.

So what is the benefit:
We can convert any number in string format from 0-9 in Hexa and still not use an alphabet i.e A, B etc
Hexa decimal value will vary from 30-39

In this way, we can treat an int as a string and then convert it back to int, doing the required type castings or conversions.

I am sharing the link for trial if needed:
http://string-functions.com/string-hex.aspx
https://codebeautify.org/hex-string-converter

How to solve this problem?
This is not a problem, I feel this was done intentionally.
but we need to tell the user what is happening/ what he is doing.
So I wanted to add a quick note and let the user know the result of his action.
Should I proceed?

@williamdes
Copy link
Member

Should I proceed?

@thesmallstar Yes, I think the best Idea is that I can see your proposal to better understand it

What bout #15147 ?

@thesmallstar
Copy link
Contributor

@williamdes , have a look at this
image

When we implement the PR, unexpected behaviour is shown, since now Alphabets are also returned by the function. I don't think it is needed, only a note for the user will do regarding what he is trying to do.

On which branch do I need to proceed?

@williamdes
Copy link
Member

I understand, thank you for the example
Use QA_5_0 for the fix

@kartik1000
Copy link
Contributor Author

@thesmallstar I agree with you. I opened the issue because I felt I was not able to understand the behavior of the function and there should be a quick note regarding what you mentioned.

@williamdes williamdes removed good first issue has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete labels Jan 12, 2020
@williamdes williamdes added the has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete label Jan 12, 2020
@williamdes williamdes added this to the 5.1.0 milestone May 14, 2020
@williamdes williamdes self-assigned this May 14, 2020
williamdes added a commit that referenced this issue May 14, 2020
Signed-off-by: William Desportes <williamdes@wdes.fr>
issues automation moved this from Reproduced to Closed May 14, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A problem or regression with an existing feature has-pr An issue that has a pull request pending that may fix this issue. The pull request may be incomplete
Projects
issues
  
Closed
Development

Successfully merging a pull request may close this issue.

4 participants