Published on InterSystems Developer Community (https://community.intersystems.com)

Home > Conversion of a variable from Binary in to Decimal

Question
Sehinde Raji · Aug 5, 2021

Conversion of a variable from Binary in to Decimal

I have been working within Objectscript for a few months and I am seeking assistance today because all of the help files within the docs.intersystems.com domain are currently down and they wont be back up until next week. (I raised a special ticket for this) 

I have been trying to figure out how to  convert a binary number 0101001 in to a decimal number using a variable called CNumber and I have tried using the method below and it hasnt worked. I think it may be due to the fact that this assumes an array or some sort. I tried using online hexadecimal calculators and the resulting output is incorrect.

If RNumber is 100 

//for i=$LENGTH(RNumber):-1:1 {
        //set RowResult = RowResult + ( $EXTRACT(RNumber(i))* Power )
        //set Power = Power * 2
  // }

The RowResult = 512 

And as you can appreciate this isn't the number I am looking for.

Does anyone know of a reliable way of obtaining the Binary to Decimal result that I desire ?

Thanks in advance

#Development Environment #ObjectScript #InterSystems IRIS
Product version: IRIS 2021.1
$ZV: 1.1

Source URL:https://community.intersystems.com/post/conversion-variable-binary-decimal