DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Hexadecimal to Decimal conversion without 2's complement

Solved!
Go to solution

Hello,

 

I'm brand new to DIAdem and attempting to use the calculator to convert a channel from hexadecimal values to multiple individual binary bit channels. 

 

I have a formula that works and formats everything the way I want, but the step going from Hex to Dec seems to be defaulting to 2's complement.  However, I need an unsigned decimal.  The formula I'm using for this step in the conversion is below:

 

ch("[1]/decarr")=CLng("&h" & ch("[1]/hexarr"))

 

So for example, I have a hex string of 88288900

When I apply the above formula I get -2010609408

However, I'm looking for 2284357888

 

Is there a simple way to achieve this?

 

Thank you in advance!

Jeff

0 Kudos
Message 1 of 3
(2,887 Views)
Solution
Accepted by topic author therabbi99

As long as I know there is no Unsigned 32 bit type in vbs.

So if you need it to be unsigned you need to split it using Left and Right.

 

MsgBox Hex(CLng("&h88288900")) & " " & CLng("&h88288900")
MsgBox Hex("&h" & Left("88288900", 4)) & " " & CLng("&h" & Left("88288900", 4)) & VBCRLF &_
       Hex("&h" & Right("88288900", 4)) & " " & CLng("&h" & Right("88288900", 4))
Message 2 of 3
(2,853 Views)

Thank you AndreasK!

 

I did as you suggested.  Unfortunately, I don't have access to write scripts.  So I'm doing everything using the Calculator.  For the benefit of others, here is what I ended up with:

 

Removes "0x" characters from front end of hexadecimal (if required)
ch("[1]/hex")=MID(INSERT CHANNEL,3)


If NOT using two's complement:

 

All functions below combined into one. Creates a channel for Bit number 12.
ch("[1]/Bit 12")=CDbl(Mid(Str(Right("0000000000000000" & Str(CLng("&h" & Left(ch("[1]/hex"), 4)),"b"),16)) & Str(Right("0000000000000000" & Str(CLng("&h" & Right(ch("[1]/hex"), 4)),"b"),16)),(33-12),1))

 

Splits hexadecimal and converts each half to decimal
ch("[1]/dec1")=CLng("&h" & Left(ch("[1]/hex"), 4))
ch("[1]/dec2")=CLng("&h" & Right(ch("[1]/hex"), 4))

 

Converts each half to binary
ch("[1]/bin1")=Str(ch("[1]/dec1"),"b")
ch("[1]/bin2")=Str(ch("[1]/dec2"),"b")

 

Pads front end of binary in order to get 16 bits
ch("[1]/bin1padded")=Right("0000000000000000" & ch("[1]/bin1"),16)
ch("[1]/bin2padded")=Right("0000000000000000" & ch("[1]/bin2"),16)

 

Combines 2 binary strings
ch("[1]/bin")=Str(ch("[1]/bin1padded")) & Str(ch("[1]/bin2padded"))

 

Creates a channel for Bit number 12
ch("[1]/Bit 12")=CDbl(Mid(ch("[1]/bin"),(33-12),1))

 

Cheers!

0 Kudos
Message 3 of 3
(2,841 Views)