Wednesday, September 12, 2012

Binary to Decimal function in Powerbuilder

This script below is the user function in Powerbuilder to convert Binary number into Decimal number.

Create function name: f_bintodec, set Integer as return value, and add sBin as parameter. sBin should be String type, and choose Value as Pass By.


Then add the script below

1:  int iDec, i, n  
2:    
3:  sBin = Reverse(sBin)  
4:  n = 1  
5:    
6:  FOR i = 1 TO Len(sBin)  
7:   iDec += Long(Mid(sBin, i, 1)) * n  
8:   n = 2 * n   
9:  NEXT  
10:    
11:  RETURN iDec  

To use the script, just write

1:  Integer iResult  
2:    
3:  iResult = f_bintodec("10110000")  

No comments:

Post a Comment