#! /usr/bin/env python # def ubvec_and ( n, ubvec1, ubvec2 ): #*****************************************************************************80 # ## UBVEC_AND computes the AND of two unsigned binary vectors. # # Discussion: # # A UBVEC is a vector of N binary digits. # # A UBVEC can be interpreted as a binary representation of an # unsigned integer, with the first entry being the coefficient of # 2^(N-1) and the last entry the coefficient of 1. # # UBVEC # # ----- -- # 00000 0 # 00001 1 # 00010 2 # 10000 16 # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 November 2015 # # Author: # # John Burkardt # # Parameters: # # Input, integer N, the length of the vectors. # # Input, integer UBVEC1(N), UBVEC2(N), the vectors. # # Input, integer VALUE(N), the AND of the two vectors. # import numpy as np value = np.zeros ( n ) for i in range ( 0, n ): value[i] = min ( ubvec1[i], ubvec2[i] ) return value def ubvec_and_test ( ): #*****************************************************************************80 # #% UBVEC_AND_TEST tests UBVEC_AND # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 November 2015 # # Author: # # John Burkardt # import platform from i4_uniform_ab import i4_uniform_ab from ubvec_to_ui4 import ubvec_to_ui4 from ui4_to_ubvec import ui4_to_ubvec n = 10 seed = 123456789 print ( '' ) print ( 'UBVEC_AND_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' UBVEC_AND computes the AND of two' ) print ( ' unsigned binary vectors representing unsigned integers' ) print ( '' ) print ( ' I J K = I AND J' ) print ( '' ) for test in range ( 0, 10 ): i, seed = i4_uniform_ab ( 0, 100, seed ) j, seed = i4_uniform_ab ( 0, 100, seed ) ubvec1 = ui4_to_ubvec ( i, n ) ubvec2 = ui4_to_ubvec ( j, n ) ubvec3 = ubvec_and ( n, ubvec1, ubvec2 ) k = ubvec_to_ui4 ( n, ubvec3 ) print ( ' %8d %8d %8d' % ( i, j, k ) ) return # # Terminate. # print ( '' ) print ( 'UBVEC_AND_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) ubvec_and_test ( ) timestamp ( )