#! /usr/bin/env python # def ubvec_reverse ( n, ubvec1 ): #*****************************************************************************80 # ## UBVEC_REVERSE reverses a UBVEC. # # 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), the vector to be reversed. # # Output, integer UBVEC2(N), the reversed vector. # import numpy as np ubvec2 = np.zeros ( n ) for i in range ( 0, n ): ubvec2[i] = ubvec1[n-1-i] return ubvec2 def ubvec_reverse_test ( ): #*****************************************************************************80 # ## UBVEC_REVERSE_TEST tests UBVEC_REVERSE. # # Licensing: # # This code is distributed under the GNU LGPL license. # # Modified: # # 22 November 2015 # # Author: # # John Burkardt # import platform from ubvec_random import ubvec_random n = 5 print ( '' ) print ( 'UBVEC_REVERSE_TEST' ) print ( ' Python version: %s' % ( platform.python_version ( ) ) ) print ( ' UBVEC_REVERSE reverses an unsigned binary vector.' ) print ( '' ) print ( ' UBVEC Reversed' ) print ( '' ) seed = 123456789 for i in range ( 0, 5 ): ubvec1, seed = ubvec_random ( n, seed ) ubvec2 = ubvec_reverse ( n, ubvec1 ) print ( ' ', end = '' ) for j in range ( 0, n ): print ( '%d' % ( ubvec1[j] ), end = '' ) print ( ' ', end = '' ) for j in range ( 0, n ): print ( '%d' % ( ubvec2[j] ), end = '' ) print ( '' ) # # Terminate. # print ( '' ) print ( 'UBVEC_REVERSE_TEST' ) print ( ' Normal end of execution.' ) return if ( __name__ == '__main__' ): from timestamp import timestamp timestamp ( ) ubvec_reverse_test ( ) timestamp ( )