#! /usr/bin/env python # def i4_to_l4vec ( i4, n ): #*****************************************************************************80 # ## I4_TO_L4VEC converts an I4 into an L4VEC. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 21 November 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer I4, the integer. # # Input, integer N, the dimension of the vector. # # Output, bool L4VEC(N), the vector of logical values. # import numpy as np l4vec = np.zeros ( n, dtype = np.bool ) for i in range ( n - 1, -1, -1 ): l4vec[i] = ( ( i4 % 2 ) == 1 ) i4 = ( i4 // 2 ) return l4vec def i4_to_l4vec_test ( ): #*****************************************************************************80 # ## I4_TO_L4VEC_TEST tests I4_TO_L4VEC. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 11 September 2018 # # Author: # # John Burkardt # print ( '' ) print ( 'I4_TO_L4VEC_TEST' ) print ( ' I4_TO_L4VEC converts an I4 to an L4VEC.' ) print ( '' ) print ( ' I4 L4VEC' ) print ( '' ) n = 8 for i4 in range ( 0, 11 ): l4vec = i4_to_l4vec ( i4, n ) print ( ' %2d: ' % ( i4 ), end = '' ) for j in range ( 0, n ): print ( ' %1d' % ( l4vec[j] ), end = '' ) print ( '' ) # # Terminate. # print ( '' ) print ( 'I4_TO_L4VEC_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) i4_to_l4vec_test ( ) timestamp ( )