How do I convert a 64bit number to hexadecimal in excel? - excel

I'm trying DEC2HEX(1000000000050000000) but it comes out as #NUM! as the number is too large for this function.
Is there another function I could use to turn this number into hexadecimal?

If you want to convert a decimal number to a 64 bit hex string, assuming that the decimal number is in cell A1 you can use the following:
=CONCATENATE(DEC2HEX(A1/2^32),DEC2HEX(MOD(A1,2^32),8))
This will work up to decimal value of 18,446,744,073,709,500,000 or hex value of 0xfffffffffffff800.
Bonus:
To convert from hex string to decimal, assuming that the 64bit hex string is in cell A1 and contains 16-characters then you can use the following:
=HEX2DEC(LEFT(A1,8))*2^32+HEX2DEC(RIGHT(A1,8))
You can adjust the number of characters in the LEFT(text,[num_chars]) to better suit your needs.
If your hex string has a 0x then you can use the following:
=HEX2DEC(MID(A1,3,8))*2^32+HEX2DEC(RIGHT(A1,8))

I found a simple solution for converting HEX to DEC and vice versa without the limits of characters.
HEX to DEC: use DECIMAL(input number or cell coordinates, input base number)
Case 1: I want to convert hex value "3C" to decimal, the formula is DECIMAL(3C, 16).
Case 2: I want to convert binary value "1001" to decimal, the formula is DECIMAL(1001, 2).
DEC to HEX: use BASE(input number or cell coordinates, output base number)
Case 1:I want to convert number value "1500" to hexadecimal, the formula is BASE(1500, 16)
Case 2:I want to convert number value "1500" to binary, the formula is BASE(1500, 2)

The DEC2HEX function has a limit of 549,755,813,887, try this formula it works for numbers up to 281,474,976,710,655.
=DEC2HEX(A7/(16^9),3)&DEC2HEX(MOD(A7,16^9),9)

There is a free add-in available that will handle that: Xnumbers
Seems to work OK:
=cvDecBase("1000000000050000000",16) --> DE0B6B3AA5EF080

Long formula but it is working for 64-HEX characters:
=HEX2DEC(MID(A24,1,8))*2^512 *(4) +HEX2DEC(MID(A24,9,8))*2^512 *(2) +HEX2DEC(MID(A24,17,8))*2^512+HEX2DEC(MID(A24,25,8))*2^256+HEX2DEC(MID(A24,33,8))*2^128+HEX2DEC(MID(A24,41,8))*2^64+HEX2DEC(MID(A24,49,8))*2^32+HEX2DEC(MID(A24,57,8))
please note: (*4) = *4 (remove brackets) and: (*2) = *2 (remove brackets)
also note: all 64 character must be present like the following example:
0000000000000000000000000000000000000000000000000000000000000fd1

Related

Extract number as an an integer from a string

I have some data which is badly formatted ( inherited) after some manipulation and some concatenation I have something resembling the following in a string
"SIGNAGE -- 11 Requires door signage. "
My table has to cross reference a some data from a VLOOKUP and then tries to get the first chars in a pattern after the --
My formula is this
=IF(VLOOKUP($C3,DoorCheck!$D3:$AD79,19,FALSE)<>"",LEFT((RIGHT((VLOOKUP($C3,DoorCheck!$D3:$AD79,19,FALSE)), LEN((VLOOKUP($C3,DoorCheck!$D3:$AD79,19,FALSE)))-SEARCH("--", (VLOOKUP($C3,DoorCheck!$D3:$AD79,19,FALSE)),1)-2)),2),"")
This successfully gives me the number 11.
My problem is that the number is being treated as a string and not as a numeric value.
What am I missing?
Use NUMBERVALUE() function to convert a string into a number.
I often use the trick when getting numbers out of text with LEFT(), MID() or RIGHT() to do a "*1" as the final step.
=mid(....) *1
for example,
So, yours would be :
=IF(VLOOKUP($C3,DoorCheck!$D3:$AD79,19,FALSE)<>"",LEFT((RIGHT((VLOOKUP($C3,DoorCheck!$D3:$AD79,19,FALSE)), LEN((VLOOKUP($C3,DoorCheck!$D3:$AD79,19,FALSE)))-SEARCH("--", (VLOOKUP($C3,DoorCheck!$D3:$AD79,19,FALSE)),1)-2)),2),"")*1

Converting padded string to fixed decimal in Alteryx

I have a large text file with no headers with fields delimited by a fixed width. All numeric fields are padded with zeros. I want to import this into Alteryx using field settings from a flat file.
Some of my fields should have the format Fixed Decimal, for example the "Regular Cost" column is a fixed decimal 9.04 - 5 decimal places before the decimal point and four following. Input example is "000026300". Desired output is 2.63.
I can't figure out the Length and Scale requirements for this to work.
Length = 9, Scale = 4 gives the error
Regular Cost: "000023600.0000" was too long to fit in this FixedDecimal.
Example image
Apparently it doesn't like the missing decimal point. If you read the file as a string, then add the decimal to the correct location in the string, e.g. read it in and force the field length to 10, then use the formula...
Left([Field_1],5) + "." + Left(Right([Field_1],4),3)
... it will look as expected. Then you can map it to a Double or a FixedDecimal 10.4

HEX2OCT formula in MS Excel returns incorrect result

While converting the hexadecimal value "FFFFFFFF00" into octal value using Hex2Oct of MS Excel, it should return "Error string" as per the rules mentioned here:
If number is negative, HEX2OCT ignores places and returns a 10-character octal number.
If number is negative, it cannot be less than FFE0000000, and if number is positive, it cannot be greater than 1FFFFFFF.
If number is not a valid hexadecimal number, HEX2OCT returns the #NUM! error value.
If HEX2OCT requires more than places characters, it returns the #NUM! error value.
If places is not an integer, it is truncated.
If places is nonnumeric, HEX2OCT returns the #VALUE! error value.
If places is negative, HEX2OCT returns the #NUM! error value.
But it computes and returns as "7777777400" without considering the rules/remarks mentioned in the link.
For example:
While calculating HEX2OCT,
As per Excel rule, If number is positive, it cannot be greater than 1FFFFFFF(hex)<->3777777777(oct)<->536870911(decimal).
But while calculating the HEX2OCT for FFFFFFFF00(hex) <-> 7777777400(oct) <-> 1099511627520(decimal).
Here the hex value FFFFFFFF00 is greater than 1FFFFFFF, but MS Excel does not return the error string instead it returns the converted octal value.
Can anyone explain why?
FFFFFFFF00 is actually well within the range of hex2oct because it is a negative number.
According to that documentation the largest negative number it can handle is FFE0000000 which when converted to decimal is -536870912. Converting your "big" hex over to decimal yields -256.
The reason the value of FFFFFFFF00 looks so big is because it's a negative number. The first bit is set to 1 (when converted to binary) which signifies that the number is negative. Negatives are computed in binary using two's complement which is found by flipping each bit and then adding 1 to the number.
Undoing the two's complement:
For your big number, the binary representation is:
1111111111111111111111111111111100000000
Subtracting 1:
1111111111111111111111111111111011111111
Flipping all the bits:
0000000000000000000000000000000100000000
Which is 256
So.. basically if the hex looks big, but the first bit is 1 then it's actually a small negative and well within your range of allowable values.
Lastly, when you hex2oct you don't get a negative sign for these because we are still not in decimal notation. The first bit of your octal is still a 1 (when converted to binary) since it's still the same number, just represented in a different counting system.
The clue lies earlier in the documentation page you quote:
The HEX2OCT function syntax has the following arguments:
Number Required. The hexadecimal number you want to convert. Number cannot contain more than 10 characters. The most significant
bit of number is the sign bit. The remaining 39 bits are magnitude
bits. Negative numbers are represented using two's-complement notation.
The hex value FFFFFFFF00 corresponds the binary value
1111 1111 1111 1111 1111 1111 1111 1111 0000 0000
and as the documentation says, "the most significant bit is the sign bit ... two's complement notation". So this value represents a negative number. By the rules of two's complement, it actually represents -256. And this is fine, because it is not "less than FFE0000000", as FFE0000000 is -2097152.
If you actually want to treat FFFFFFFF00 as an unsigned quantity, and get the octal representation of decimal 1099511627520, you'll need to use another method.

convert 16 bit decimal into two 8 bit decimal in excel

I am finding a formula which can convert a 16 bit binary number into two separate decimal number
0000000110010000 -> 0x0190
I want the decimal number to be 1 and 144
I have 50 columns(say M1 to M50) of binary numbers so need to make a generic formula for this
If M1 contains your binary number (as a text string), then use
=BIN2DEC(LEFT(M1, 8))
to extract the left part
and
=BIN2DEC(RIGHT(M1, 8))
to extract the right part.
If you want the result in the same cell then use something like
=BIN2DEC(LEFT(M1, 8)) & "|" & BIN2DEC(RIGHT(M1, 8))
where the | is an arbitrary separator, which you can change or omit to suit personal taste.
are they all exactly 16 characters long? You could do:
=BIN2DEC(RIGHT(M1,8))
=BIN2DEC(LEFT(M1,8))

Excel : Find only Hexa decimals from 1 cell

I'm a newbie on Excel.
So I have a list of some names ending with Hexa decimals. And some names, that doesn't have any.
My mission is to see only those names with Hexa decimals. (Mabye somehow filter them out)
Column:
BFAXSPOINTDEVBAUHOFLAN2AD
BFAXSQLBAUHOFLAN207
BFAXSQLDEVBAUHOFLAN27A
BFREPDEVBAUHOFLAN258
BFREPORTINGBAUHOFLAN20B
COBALTSEA02900
COBALTSEAVHOST900
DIRECTO8000
DIRECTO9000
DIRECTODCDIRECTOLA009
DYNAMAEBSSISE006
SURVEYEBSSISE006
KVMSRV00",
KVMSRV01",
KVMSRV02",
ASR
CACTI
DBSYNC",
DTV
and so on...
The Function HEX2DEC will help you achieve what you want - it attempts to convert a number as a hexidecimal, into a decimal. If it is not a valid Hex input, it will produce an error.
The key is understanding how many digits you expect your decimal to be - is it the last 5 characters; the last 10; etc. Also note that there is a risk that random text / numbers will be seen as hexidecimal when really that's not what it represents [but that's a problem with the question as you have laid it out; going solely based on the text provided, all we can see is whether a particular cell creates a valid Hexidecimal].
The full formula would look like this[assuming your data starts in A1, and that your Hexidecimal numbers are expected to be 6 characters long, this goes in B1 and is copied down]:
=ISERROR(HEX2DEC(RIGHT(A1,6)))
This takes the 6 rightmost characters of a cell, and attempts to convert it from Hex to Decimal. If it fails, it will produce TRUE [because of ISERROR]; if it succeeds, it will produce FALSE.
Then simply filter on your column to see the subset of results you care about.
Consider the following UDF:
Public Function EndsInHex(r As Range) As Boolean
Dim s As String, CH As String
s = r(1).Text
CH = Right(s, 1)
If CH Like "[A-F]" Or CH Like "[0-9]" Then
EndsInHex = True
Else
EndsInHex = False
End If
End Function
For the string to end in a hex, the last character must be a hex.

Resources