Jump to content

Binary function used for reversing hexadecimals


Relive
 Share

Recommended Posts

I was curious of trying to find the binaries of a decimal value so I thought of using Binary(), but it yielded a result that solved my other problem of my older project. It was painful to try and solve the problem months ago but this accidental approach really helped me out.

$decimal = 69
$binary = binary($decimal)

MsgBox(0, "", _
"decimal: " & $decimal & @CR & _
"binary: " & $binary & @CR & _ ;it made it reversed hex already? where's 0s and 1s?
"hexadecimal v1: " & hex($binary) ) ;same as binary? ok, it removed 0x but 0x indicates a set as hex.

So 69 wasn't converted to 0s and 1s but instead Binary() gave me 0x45000000, which is the reversed hex (little endian) of 0x00000045. There's nothing in the Help file that clearly explains the usage of this. Then I tried converting the result with Hex(), and ironically it yield the same result but removed the 0x. I thought 0x denotes an alphanumeric set as hexadecimal?

Anyways, I wished this function was better documented so I wouldn't have to spend months just to solve something so simple. I wasn't on it for 24/7 but you get the point.

Link to comment
Share on other sites

How would a concatenation on a binary data type work? This is a given for programmers: There is an implicit binary to string conversion. You are looking at the string representation of the binary data type, not the binary data itself. To do that the function String is called which makes it more or less human-readable, hence the 0x. For Hex that would be inappropriate.

I found something in the help file that would have helped you, but it's not in a convenient place. It describes the transformation that String does on binary data. See Remarks on BinaryToString (which could be a sensible place to look btw):

Unlike String() which returns a hexidecimal representation of binary data, this function will assume the binary data is a string value and convert it appropriately.

To print 1s and 0s would be meaningless. Data is data no matter the representation: Hex is more convenient for everyone.

Link to comment
Share on other sites

To print 1s and 0s would be meaningless. Data is data no matter the representation: Hex is more convenient for everyone.

I have to throw my 2p. Hex is convenient for programmers. I would say that as a counting system, hex is not top dog in the ranking order of usefulness. It is the number of prime factors that I would say have bearing on this, and decimal is slightly better than hex but less useful than dodecimal. enz....For representing binary hex is particularly convenient.

Link to comment
Share on other sites

I don't know why I said dodecimal was better than decimal: Although it has more factors, it actually has the same number of prime factors, how embarrassing! I don't know!

If I want to shift a bunch of ones to the left, I like to see them move.

Edited by czardas
Link to comment
Share on other sites

  • 1 month later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...