of_decimal


pfcapsrv.pbl   >   pfc_n_cst_numerical   >   of_decimal   

Full name pfc_n_cst_numerical.of_decimal
Access public
Extend of long
Return value long
Prototype public function long of_decimal(string)

Name Datatype
No Data

Name Datatype
lch_char char[]
li_cnt integer
ll_decimal long
ll_len long
ll_null long

public function long of_decimal (string as_binary);//////////////////////////////////////////////////////////////////////////////
//
//	Function:  		of_Decimal
//
//	Access: 			public
//
//	Arguments:
//	as_binary		Binary string value whose Decimal representation needs to be 
//						determined. (e.g "111")
//
//	Returns: 		long
//						The positive Decimal representation of the Binary number (e.g. 7).
//						If any argument's value is NULL, function returns NULL.
//						If any argument's value is Invalid, function returns -1.
//
//	Description:   Determines the Decimal representation of a Binary number.
//
//////////////////////////////////////////////////////////////////////////////
//
//	Revision History
//
//	Version
//	5.0   Initial version
//
//////////////////////////////////////////////////////////////////////////////
//
//	Copyright © 1996-1997 Sybase, Inc. and its subsidiaries.  All rights reserved.
//	Any distribution of the PowerBuilder Foundation Classes (PFC)
//	source code by other than Sybase, Inc. and its subsidiaries is prohibited.
//
//////////////////////////////////////////////////////////////////////////////

integer 	li_cnt
long		ll_len
char		lch_char[]
long		ll_decimal=0

//Check parameters
If IsNull(as_binary) or Len(as_binary)<=0 then
	long ll_null
	SetNull(ll_null)	
	Return ll_null
End If

//Get the length
ll_len = Len(as_binary)

//Move string into arrach of characters
lch_char = as_binary

For li_cnt = 1 to ll_len
	//Make sure only 0's and 1's are present
	If (Not lch_char[li_cnt]='1') AND (Not lch_char[li_cnt]='0') Then
		Return -1
	End If
	//Build the decimal equivalent
	ll_decimal = ll_decimal + (long(lch_char[li_cnt]) * (2 ^ (ll_len - li_cnt)))
Next

Return ll_decimal
end function

     
Name Owner
pfc_n_cst_numerical.of_bitwisenot pfc_n_cst_numerical

     
Name Owner
systemfunctions.isnull systemfunctions
systemfunctions.len systemfunctions
systemfunctions.long systemfunctions
systemfunctions.setnull systemfunctions

     
Full name
No Data

     
Name Scope
No Data