# HEXLIB

I already own the source code for HEXLIB and know how external functions and modules work.

What is needed is the actual source code for IMP, that is, what is the line of code below for

LET Imp = ????????????????

in the block of code below:

DEF And( a, b)
LET m = 1
LET b = Int( b)
DO
CALL Divide( a, 2, a, aa)
CALL Divide( b, 2, b, bb)
LET r = r + m * aa * bb
LET m = 2 * m
IF b = -1 then
LET r = r + m * a
EXIT DO
END IF
LOOP while b <> 0
LET And = r
END DEF

DEF Or( a, b)
DECLARE DEF And
LET Or = a + b - And( a, b)
END DEF

DEF Xor( a, b)
DECLARE DEF And
LET Xor = a + b - 2 * And( a, b)
END DEF

DEF Imp( a, b)
DECLARE DEF And ! , Or, Xor
LET Imp = ??????????????
END DEF

I already programmed NOR, and hence IMP, as an internal function, but I want the above line of code which should run faster from the compiled external library.

### IMP Function

I don't know exactly how the creator of HEXLIB implemented the function but here's one in TB that gives the same output:

There's no bitwise NOT in TB but here's the general idea:

IMP = (NOT x) OR (x AND y)

or in HEXLIB-type notation:

IMP = OR(NOT(x), AND(x,y))

Tom Lake

### IMP Function

Tom:

Thanks for the forum response. What I wanted was a numeric implementation of IMP in the same vein as the HexLib And implementation by the language developer.

Shy of that, here is my implementation of Not as Flip_bits\$

! LIBRARY "HEXLIB.TRC"
! DECLARE DEF And, Or, Xor, Convert, Bin\$
!
! DECLARE DEF Imp, Nor, Flip_bits\$
!
!
! Here is the implementation of bit-wise Not which I named
! Flip_bits\$ below, and my other implementations
!
!
! FUNCTION Nor( a, b) ! Negation of Nor by numerical ( -1 *)
! !
! LET Nor = ( -1 * ( a + b - And( a, b)))
! !
! ! From HexLIB.TRU, Or = a + b - And( a, b)
! !
! END FUNCTION ! Nor( a, b)
!
!
! FUNCTION Flip_bits\$( input\$)
! !
! LET resultb\$ = input\$
! LET resultb\$ = RepStr\$( resultb\$, "1", "u")
! LET resultb\$ = RepStr\$( resultb\$, "0", "1")
! LET resultb\$ = RepStr\$( resultb\$, "u", "0")
! LET Flip_bits\$ = resultb\$
! !
! END FUNCTION ! Flip_bits\$( input\$)
! !
! !
! FUNCTION Imp( a, b)
! !
! LET p = a
! LET q = b
! !
! LET p_NOR_p = Nor( p, p)
! !
! LET Imp = Nor( Nor( Nor( p, p), q), Nor( Nor( p, p), q))
! ! Correct answer if all bits flipped
! !
! END FUNCTION ! Imp( a, b)
! !

Colin