# Binary function used for reversing hexadecimals

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

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

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

##### Share on other sites

And with everyone I meant everyone who might have an interested in the string representation of binary data, i.e. programmers.

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

##### Share on other sites

Did you ever figure this out?

I'm looking for a way to convert a Hex to its corresponding binary number so that i can manipulate the bits

##### Share on other sites

I'm looking for a way to convert a Hex to its corresponding binary number so that i can manipulate the bits

Look here.

##### Share on other sites

Thanks Czardas & thanks to UEZ for the code

spent the afternoon trying nested ifs and other loops to try and process the hex values.

Not Fun

##### Share on other sites

I'm sure you will conquer it. Any issues that you encounter, you should ask about it in Help and Support.

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...