$PBExportHeader$n_svc_bit.sru $PBExportComments$Bitwise Service forward global type n_svc_bit from n_svc_base end type end forward global type n_svc_bit from n_svc_base end type global n_svc_bit n_svc_bit forward prototypes public function string of_binary (readonly long al_decimal) public function integer of_bitwiseand (readonly integer ai_decimala, readonly integer ai_decimalb) public function integer of_bitwisenot (readonly integer ai_decimal) public function integer of_bitwiseor (readonly integer ai_decimala, readonly integer ai_decimalb) public function integer of_clearbit (readonly integer ai_decimal, readonly unsignedinteger aui_bit) public function long of_clearbit (readonly long al_decimal, readonly unsignedinteger aui_bit) public function long of_bitwiseor (readonly long al_decimala, readonly long al_decimalb) public function long of_bitwisenot (readonly long al_decimal) public function long of_bitwiseand (readonly long al_decimala, readonly long al_decimalb) public function long of_decimal (string as_binary) public function integer of_flipbit (readonly integer ai_decimal, readonly unsignedinteger aui_bit) public function long of_flipbit (readonly long al_decimal, readonly unsignedinteger aui_bit) public function boolean of_getbit (readonly long al_decimal, readonly unsignedinteger aui_bit) public function integer of_setbit (readonly integer ai_decimal, readonly unsignedinteger aui_bit) public function long of_setbit (readonly long al_decimal, readonly unsignedinteger aui_bit) public function integer of_bitwiseand (readonly integer ai_decimal[]) public function long of_bitwiseand (readonly long al_decimal[]) public function integer of_bitwiseor (readonly integer ai_decimal[]) public function long of_bitwiseor (readonly long al_decimal[]) public function integer of_bitwisexor (readonly integer ai_decimala, readonly integer ai_decimalb) public function long of_bitwisexor (readonly long al_decimala, readonly long al_decimalb) public function unsignedlong of_bitwiseor (readonly unsignedlong al_decimal[]) public function ulong of_bitwiseor (readonly unsignedlong al_decimala, readonly unsignedlong al_decimalb) end prototypes public function string of_binary (readonly long al_decimal);////////////////////////////////////////////////////////////////////////////// // // Function: of_Binary // // Access: public // // Arguments: // al_decimal unsigned long to convert to bit string // // Returns: string // // Description: Convert al_decimal to a string of 32 1's and 0's in // big-endian format i.e with LSB at position 1. // ////////////////////////////////////////////////////////////////////////////// string ls_binary unsignedint lui_cnt long ll_remainder unsignedlong lul_decimal lul_decimal = al_decimal for lui_cnt = 1 to 32 ll_remainder = mod(lul_decimal, 2) lul_decimal = lul_decimal / 2 ls_binary = ls_binary + string(ll_remainder) next return ls_binary end function public function integer of_bitwiseand (readonly integer ai_decimala, readonly integer ai_decimalb);////////////////////////////////////////////////////////////////////////////// // // Function: of_BitwiseAND // // Access: public // // Arguments: // ai_decimala // ai_decimalb // // Returns: int // // Description: Logically AND 2 numbers // // a b result // -- -- ------ // 0 0 0 // 0 1 0 // 1 0 0 // 1 1 1 // ////////////////////////////////////////////////////////////////////////////// unsignedint lui_bit int li_decimal li_decimal = 0 for lui_bit = 1 to 16 if this.of_GetBit(ai_decimala, lui_bit) and this.of_GetBit(ai_decimalb, lui_bit) then li_decimal = this.of_SetBit(li_decimal, lui_bit) end if next return li_decimal end function public function integer of_bitwisenot (readonly integer ai_decimal);////////////////////////////////////////////////////////////////////////////// // // Function: of_BitwiseNOT // // Access: public // // Arguments: // ai_decimal value to not // // Returns: none // // Description: Logically NOT all bits in a number // // a result // -- ------ // 0 1 // 1 0 // ////////////////////////////////////////////////////////////////////////////// unsignedint lui_bit int li_decimal li_decimal = 0 for lui_bit = 1 to 16 if not this.of_GetBit(ai_decimal, lui_bit) then li_decimal = this.of_SetBit(li_decimal, lui_bit) end if next return li_decimal end function public function integer of_bitwiseor (readonly integer ai_decimala, readonly integer ai_decimalb);////////////////////////////////////////////////////////////////////////////// // // Function: of_BitwiseOR // // Access: public // // Arguments: // ai_decimala // ai_decimalb // // Returns: int // // Description: Logically OR 2 numbers // // a b result // -- -- ------ // 0 0 0 // 0 1 1 // 1 0 1 // 1 1 1 // ////////////////////////////////////////////////////////////////////////////// unsignedint lui_bit int li_decimal li_decimal = 0 for lui_bit = 1 to 16 if this.of_GetBit(ai_decimala, lui_bit) or this.of_GetBit(ai_decimalb, lui_bit) then li_decimal = this.of_SetBit(li_decimal, lui_bit) end if next return li_decimal end function public function integer of_clearbit (readonly integer ai_decimal, readonly unsignedinteger aui_bit);////////////////////////////////////////////////////////////////////////////// // // Function: of_ClearBit // // Access: public // // Arguments: // ai_decimal value // aui_bit bit number to clear // // Returns: new value // // Description: Clears a given bit in a number. // ////////////////////////////////////////////////////////////////////////////// if of_GetBit(ai_decimal, aui_bit) then return ai_decimal - (2 ^ (aui_bit - 1)) end if return ai_decimal end function public function long of_clearbit (readonly long al_decimal, readonly unsignedinteger aui_bit);////////////////////////////////////////////////////////////////////////////// // // Function: of_ClearBit // // Access: public // // Arguments: // al_decimal value // aui_bit bit number to clear // // Returns: new value // // Description: Clears a given bit in a number. // ////////////////////////////////////////////////////////////////////////////// if of_GetBit(al_decimal, aui_bit) then return al_decimal - (2 ^ (aui_bit - 1)) end if return al_decimal end function public function long of_bitwiseor (readonly long al_decimala, readonly long al_decimalb);////////////////////////////////////////////////////////////////////////////// // // Function: of_BitwiseOR // // Access: public // // Arguments: // al_decimala // al_decimalb // // Returns: long // // Description: Logically OR 2 numbers // // a b result // -- -- ------ // 0 0 0 // 0 1 1 // 1 0 1 // 1 1 1 // ////////////////////////////////////////////////////////////////////////////// unsignedint lui_bit long ll_decimal ll_decimal = 0 for lui_bit = 1 to 32 if this.of_GetBit(al_decimala, lui_bit) or this.of_GetBit(al_decimalb, lui_bit) then ll_decimal = this.of_SetBit(ll_decimal, lui_bit) end if next return ll_decimal end function public function long of_bitwisenot (readonly long al_decimal);////////////////////////////////////////////////////////////////////////////// // // Function: of_BitwiseNOT // // Access: public // // Arguments: // al_decimal value to not // // Returns: none // // Description: Logically NOT all bits in a number // // a result // -- ------ // 0 1 // 1 0 // ////////////////////////////////////////////////////////////////////////////// unsignedint lui_bit long ll_decimal ll_decimal = 0 for lui_bit = 1 to 32 if not this.of_GetBit(al_decimal, lui_bit) then ll_decimal = this.of_SetBit(ll_decimal, lui_bit) end if next return ll_decimal end function public function long of_bitwiseand (readonly long al_decimala, readonly long al_decimalb);////////////////////////////////////////////////////////////////////////////// // // Function: of_BitwiseAND // // Access: public // // Arguments: // al_decimala // al_decimalb // // Returns: long // // Description: Logically AND 2 numbers // // a b result // -- -- ------ // 0 0 0 // 0 1 0 // 1 0 0 // 1 1 1 // ////////////////////////////////////////////////////////////////////////////// unsignedint lui_bit long ll_decimal ll_decimal = 0 for lui_bit = 1 to 32 if this.of_GetBit(al_decimala, lui_bit) and this.of_GetBit(al_decimalb, lui_bit) then ll_decimal = this.of_SetBit(ll_decimal, lui_bit) end if next return ll_decimal end function public function long of_decimal (string as_binary);////////////////////////////////////////////////////////////////////////////// // // Function: of_Decimal // // Access: public // // Arguments: // as_binary string to convert // // Returns: long // // Description: Convert an array of 1's and 0's in big-endian format // i.e. LSB at index 1 to a number. // ////////////////////////////////////////////////////////////////////////////// long ll_decimal unsignedint lui_cnt // Propogate the sign bit as_binary += Fill(Right(as_binary, 1), 31) // Calculate the value for lui_cnt = 1 to 32 ll_decimal = ll_decimal + (long(Mid(as_binary, lui_cnt, 1)) * (2 ^ (lui_cnt - 1))) next return ll_decimal end function public function integer of_flipbit (readonly integer ai_decimal, readonly unsignedinteger aui_bit);////////////////////////////////////////////////////////////////////////////// // // Function: of_FlipBit // // Access: public // // Arguments: // ai_decimal value // aui_bit bit number to flip // // Returns: new value // // Description: Flips a given bit in a number. // ////////////////////////////////////////////////////////////////////////////// if not this.of_GetBit(ai_decimal, aui_bit) then return this.of_SetBit(ai_decimal, aui_bit) else return this.of_ClearBit(ai_decimal, aui_bit) end if end function public function long of_flipbit (readonly long al_decimal, readonly unsignedinteger aui_bit);////////////////////////////////////////////////////////////////////////////// // // Function: of_FlipBit // // Access: public // // Arguments: // al_decimal value // aui_bit bit number to flip // // Returns: new value // // Description: Flips a given bit in a number. // ////////////////////////////////////////////////////////////////////////////// if not this.of_GetBit(al_decimal, aui_bit) then return this.of_SetBit(al_decimal, aui_bit) else return this.of_ClearBit(al_decimal, aui_bit) end if end function public function boolean of_getbit (readonly long al_decimal, readonly unsignedinteger aui_bit);////////////////////////////////////////////////////////////////////////////// // // Function: of_GetBit // // Access: public // // Arguments: // al_decimal value // aui_bit bit number to test // // Returns: boolean // // Description: Tests a given bit in a number. // ////////////////////////////////////////////////////////////////////////////// unsignedlong lul_decimal lul_decimal = al_decimal if (Mod(long(lul_decimal / 2 ^(aui_bit - 1)), 2) > 0) then return true end if return false end function public function integer of_setbit (readonly integer ai_decimal, readonly unsignedinteger aui_bit);////////////////////////////////////////////////////////////////////////////// // // Function: of_SetBit // // Access: public // // Arguments: // ai_decimal value // aui_bit bit number to set // // Returns: new value // // Description: Sets a given bit in a number. // ////////////////////////////////////////////////////////////////////////////// if not this.of_GetBit(ai_decimal, aui_bit) then return ai_decimal + (2 ^ (aui_bit - 1)) end if return ai_decimal end function public function long of_setbit (readonly long al_decimal, readonly unsignedinteger aui_bit);////////////////////////////////////////////////////////////////////////////// // // Function: of_SetBit // // Access: public // // Arguments: // al_decimal value // aui_bit bit number to set // // Returns: new value // // Description: Sets a given bit in a number. // ////////////////////////////////////////////////////////////////////////////// if not this.of_GetBit(al_decimal, aui_bit) then return al_decimal + (2 ^ (aui_bit - 1)) end if return al_decimal end function public function integer of_bitwiseand (readonly integer ai_decimal[]);//=========================================================================== // Function: of_Bitwiseand (public ) // Object: n_svc_bit //--------------------------------------------------------------------------- // Description: // Note: //--------------------------------------------------------------------------- // Parameters: // readonly Integer ai_decimal[] //--------------------------------------------------------------------------- // Returns: Integer //--------------------------------------------------------------------------- // Author: (Yeyi) Gabriel B. Abulencia //=========================================================================== long ll_upper, ll_ctr = 2, n integer li_ret ll_upper = UPPERBOUND(ai_decimal) IF ll_upper <= 1 THEN RETURN Cret.FAILURE li_ret = ai_decimal[1] DO li_ret = this.of_bitwiseand(li_ret, ai_decimal[ll_ctr]) ll_ctr ++ LOOP UNTIL ll_ctr > ll_upper RETURN li_ret end function public function long of_bitwiseand (readonly long al_decimal[]);//=========================================================================== // Function: of_Bitwiseand (public ) // Object: n_svc_bit //--------------------------------------------------------------------------- // Description: // Note: //--------------------------------------------------------------------------- // Parameters: // readonly Long al_decimal[] //--------------------------------------------------------------------------- // Returns: Long //--------------------------------------------------------------------------- // Author: (Yeyi) Gabriel B. Abulencia //=========================================================================== long ll_upper, ll_ctr = 2, n, ll_ret ll_upper = UPPERBOUND(al_decimal) IF ll_upper <= 1 THEN RETURN Cret.FAILURE ll_ret = al_decimal[1] DO ll_ret = this.of_bitwiseand(ll_ret, al_decimal[ll_ctr]) ll_ctr ++ LOOP UNTIL ll_ctr > ll_upper RETURN ll_ret end function public function integer of_bitwiseor (readonly integer ai_decimal[]);//=========================================================================== // Function: of_Bitwiseor (public ) // Object: n_svc_bit //--------------------------------------------------------------------------- // Description: // Note: //--------------------------------------------------------------------------- // Parameters: // readonly Integer ai_decimal[] //--------------------------------------------------------------------------- // Returns: Integer //--------------------------------------------------------------------------- // Author: (Yeyi) Gabriel B. Abulencia //=========================================================================== long ll_upper, ll_ctr = 2, n integer li_ret ll_upper = UPPERBOUND(ai_decimal) IF ll_upper <= 1 THEN RETURN Cret.FAILURE li_ret = ai_decimal[1] DO li_ret = this.of_bitwiseor(li_ret, ai_decimal[ll_ctr]) ll_ctr ++ LOOP UNTIL ll_ctr > ll_upper RETURN li_ret end function public function long of_bitwiseor (readonly long al_decimal[]);//=========================================================================== // Function: of_Bitwiseor (public ) // Object: n_svc_bit //--------------------------------------------------------------------------- // Description: // Note: //--------------------------------------------------------------------------- // Parameters: // readonly Long al_decimal[] //--------------------------------------------------------------------------- // Returns: Long //--------------------------------------------------------------------------- // Author: (Yeyi) Gabriel B. Abulencia //=========================================================================== long ll_upper, ll_ctr = 2, n, ll_ret ll_upper = UPPERBOUND(al_decimal) IF ll_upper <= 1 THEN RETURN Cret.FAILURE ll_ret = al_decimal[1] DO ll_ret = this.of_bitwiseor(ll_ret, al_decimal[ll_ctr]) ll_ctr ++ LOOP UNTIL ll_ctr > ll_upper RETURN ll_ret end function public function integer of_bitwisexor (readonly integer ai_decimala, readonly integer ai_decimalb);////////////////////////////////////////////////////////////////////////////// // // Function: of_BitwiseXOR // // Access: public // // Arguments: // ai_decimala // ai_decimalb // // Returns: int // // Description: Logically XOR 2 numbers // // a b result // -- -- ------ // 0 0 0 // 0 1 1 // 1 0 1 // 1 1 0 // ////////////////////////////////////////////////////////////////////////////// unsignedint lui_bit int li_decimal li_decimal = 0 for lui_bit = 1 to 16 if this.of_GetBit(ai_decimala, lui_bit) <> this.of_GetBit(ai_decimalb, lui_bit) then li_decimal = this.of_SetBit(li_decimal, lui_bit) end if next return li_decimal end function public function long of_bitwisexor (readonly long al_decimala, readonly long al_decimalb);////////////////////////////////////////////////////////////////////////////// // // Function: of_BitwiseXOR // // Access: public // // Arguments: // al_decimala // al_decimalb // // Returns: long // // Description: Logically XOR 2 numbers // // a b result // -- -- ------ // 0 0 0 // 0 1 1 // 1 0 1 // 1 1 0 // ////////////////////////////////////////////////////////////////////////////// unsignedint lui_bit long ll_decimal ll_decimal = 0 for lui_bit = 1 to 32 if this.of_GetBit(al_decimala, lui_bit) <> this.of_GetBit(al_decimalb, lui_bit) then ll_decimal += (2 ^ (lui_bit - 1)) end if next return ll_decimal end function public function unsignedlong of_bitwiseor (readonly unsignedlong al_decimal[]);//=========================================================================== // Function: of_Bitwiseor (public ) // Object: n_svc_bit //--------------------------------------------------------------------------- // Description: // Note: //--------------------------------------------------------------------------- // Parameters: // readonly UnsignedLong al_decimal[] //--------------------------------------------------------------------------- // Returns: UnsignedLong //--------------------------------------------------------------------------- // Author: (Yeyi) Gabriel B. Abulencia //=========================================================================== long ll_upper, ll_ctr = 2, n, ll_ret ll_upper = UPPERBOUND(al_decimal) IF ll_upper <= 1 THEN RETURN Cret.FAILURE ll_ret = al_decimal[1] DO ll_ret = this.of_bitwiseor(ll_ret, al_decimal[ll_ctr]) ll_ctr ++ LOOP UNTIL ll_ctr > ll_upper RETURN ll_ret end function public function ulong of_bitwiseor (readonly unsignedlong al_decimala, readonly unsignedlong al_decimalb);////////////////////////////////////////////////////////////////////////////// // // Function: of_BitwiseOR // // Access: public // // Arguments: // al_decimala // al_decimalb // // Returns: long // // Description: Logically OR 2 numbers // // a b result // -- -- ------ // 0 0 0 // 0 1 1 // 1 0 1 // 1 1 1 // ////////////////////////////////////////////////////////////////////////////// unsignedint lui_bit ulong ll_decimal ll_decimal = 0 for lui_bit = 1 to 32 if this.of_GetBit(al_decimala, lui_bit) or this.of_GetBit(al_decimalb, lui_bit) then ll_decimal = this.of_SetBit(ll_decimal, lui_bit) end if next return ll_decimal end function on n_svc_bit.create call super::create end on on n_svc_bit.destroy call super::destroy end on
- Sources
- Kodigo
- OpenExplorer
- n_svc_bit.sru
File: n_svc_bit.sru
Size: 20290
Date: Mon, 07 Apr 2008 21:31:14 +0200
Size: 20290
Date: Mon, 07 Apr 2008 21:31:14 +0200
- n_svc_base n_svc_bit(sru)
- of_binary (readonly long al_decimal) returns string
- of_bitwiseand (readonly integer ai_decimal[]) returns integer
- of_bitwiseand (readonly integer ai_decimala, readonly integer ai_decimalb) returns integer
- of_bitwiseand (readonly long al_decimal[]) returns long
- of_bitwiseand (readonly long al_decimala, readonly long al_decimalb) returns long
- of_bitwisenot (readonly integer ai_decimal) returns integer
- of_bitwisenot (readonly long al_decimal) returns long
- of_bitwiseor (readonly integer ai_decimal[]) returns integer
- of_bitwiseor (readonly integer ai_decimala, readonly integer ai_decimalb) returns integer
- of_bitwiseor (readonly long al_decimal[]) returns long
- of_bitwiseor (readonly long al_decimala, readonly long al_decimalb) returns long
- of_bitwiseor (readonly unsignedlong al_decimal[]) returns unsignedlong
- of_bitwiseor (readonly unsignedlong al_decimala, readonly unsignedlong al_decimalb) returns ulong
- of_bitwisexor (readonly integer ai_decimala, readonly integer ai_decimalb) returns integer
- of_bitwisexor (readonly long al_decimala, readonly long al_decimalb) returns long
- of_clearbit (readonly integer ai_decimal, readonly unsignedinteger aui_bit) returns integer
- of_clearbit (readonly long al_decimal, readonly unsignedinteger aui_bit) returns long
- of_decimal (string as_binary) returns long
- of_flipbit (readonly integer ai_decimal, readonly unsignedinteger aui_bit) returns integer
- of_flipbit (readonly long al_decimal, readonly unsignedinteger aui_bit) returns long
- of_getbit (readonly long al_decimal, readonly unsignedinteger aui_bit) returns boolean
- of_setbit (readonly integer ai_decimal, readonly unsignedinteger aui_bit) returns integer
- of_setbit (readonly long al_decimal, readonly unsignedinteger aui_bit) returns long