X-Git-Url: http://gitweb.scilab.org/?p=scilab.git;a=blobdiff_plain;f=scilab%2Fmodules%2Felementary_functions%2Fhelp%2Fen_US%2Fbitwise%2Fbitcmp.xml;h=b947df7d9407273d377c0e6a41d382654b2b8413;hp=8cf44d3b75670fd9e0b83448b97091e93fbb87d8;hb=b919d6d4dd79f45aabad6b91aa2fd98695170ebc;hpb=dc43fe423fcb72cdb633ec7245e643778ebca0f2 diff --git a/scilab/modules/elementary_functions/help/en_US/bitwise/bitcmp.xml b/scilab/modules/elementary_functions/help/en_US/bitwise/bitcmp.xml index 8cf44d3..b947df7 100644 --- a/scilab/modules/elementary_functions/help/en_US/bitwise/bitcmp.xml +++ b/scilab/modules/elementary_functions/help/en_US/bitwise/bitcmp.xml @@ -1,10 +1,7 @@ - + bitcmp - bitwise complement + bitwise complement of integers Syntax @@ -27,40 +27,66 @@ - Parameters + Arguments - x : - - - a m-by-n matrix of doubles - or a m1-by-m2-by-...-by-mm hypermatrix of doubles - or a m-by-n matrix of unsigned integers (uint8, uint16 or uint32). - Must contain positive integer values. - - - - - bitnum : + x, y - - a m-by-n matrix of doubles - or a m1-by-m2-by-...-by-mm hypermatrix of doubles - or a m-by-n matrix of unsigned integers (uint8, uint16 or uint32). - The input n must be in the range 1, 2, ..., bitmax - where bitmax is the maximum number of bits in x. - bitnum must contain positive integer values. The default value for bitnum is bitmax. - + arrays of signed or unsigned integers (int8, .., uint64), or of positive decimal + integers. Hypermatrix supported. x and y + have the same integer type and the same size. + - y : + bitnum - - a m-by-n matrix of doubles - or a m1-by-m2-by-...-by-mm hypermatrix of doubles - or a m-by-n matrix of unsigned integers. - + positive encoded or decimal integer, or array of positive encoded or decimal + integers of size equal to size(x): bits #1 to #bitnum of x + are considered and inversed. According to the integer type of + x, bitnum must be in the interval + [1, bitmax] with bitmax as follows: + + + + + + + + + + + + + + + + + + + + + + + +
 inttypeÂ : bitmaxÂ : int8 uint8 int16 uint16 int32 uint32 int64 uint64 decimal 8 8 16 16 32 32 64 64 1024
+ + The default bitnum value depends on the input integer + type: + + + bitnum = bitmax for encoded integers + + + bitnum = 53 for decimal integers + x â¤ 1/%eps + + + bitnum = int(log2(x))+1 for decimal integers + x > 1/%eps. + + +
@@ -68,37 +94,243 @@ Description - Given an unsigned integer x, this function returns the unsigned integer y - which is the integer corresponding to the complementary of the binary - form of x. + bitcmp(x) computes the binary complement of each element of + x, and provides it in the corresponding element of y. - The integer bitnum sets the maximum number of bits. + In the following description, 2^0 corresponds to the bit #1. An integer whose highest + bit on is #n, is in [2^(n-1),Â 2^n-1]. - If the bits number of the x binary representation is less than the - bitmax number (8,16 or 32) then the bits '1' are added to the - complementary in order to have bitmax number (8, 16 or 32) for the - complementary. + For x such that abs(x) â¥ 2^bitnum, + its bits #(bitnum+1) to #(int(log2(x))+1) + are ignored. Only its bits #1 to #bitnum + are considered and inversed. - If only one input argument is given, x must be a matrix of unsigned integers. + Example: + +--> bitget(180, 1:8) + ans = + 0. 0. 1. 0. 1. 1. 0. 1. +--> bitcmp(180, 4) + ans = + 11. +--> bitget(11, 1:8) + ans = + 1. 1. 0. 1. 0. 0. 0. 0. + + + + For x such that abs(x) < 2^bitnum, + bits #(int(log2(x))+2) to #bitnum are padded + with 0. Then all bits #1 to #bitnum are considered + and inversed. + + + Example: + +--> x = 30; int(log2(30))+2 + ans = + 6. +--> bitget(30, 1:10) + ans = + 0. 1. 1. 1. 1. 0. 0. 0. 0. 0. +--> bitcmp(30, 7) + ans = + 97. +--> bitget(97, 1:10) + ans = + 1. 0. 0. 0. 0. 1. 1. 0. 0. 0. + Examples + b = bitget(x, 1:8) + b = + 1 0 1 1 0 0 0 0 + +--> c = bitcmp(x, 8) + c = + 242 + +--> bitget(c, 1:8) + ans = + 0 1 0 0 1 1 1 1 + +--> 1 - b + ans = + 0 1 0 0 1 1 1 1 +]]> + + + Negative encoded integers are accepted: + + + bitcmp(int8([-71 -34 -1 0 33 70])) + ans = + 70 33 0 -1 -34 -71 + +--> bitcmp(int8([-71 -34 -1 0 33 70]), 8) + ans = + 70 33 0 -1 -34 -71 + +--> bitcmp(int8([-71 -34 -1 0 33 70]), 7) + ans = + 70 33 0 127 94 57 + +--> bitcmp(int8([-71 -34 -1 0 33 70]), 6) + ans = + 6 33 0 63 30 57 + +--> bitcmp(int8([-71 -34 -1 0 33 70]), 5) + ans = + 6 1 0 31 30 25 + +--> bitcmp(int8([-71 -34 -1 0 33 70]), 4) + ans = + 6 1 0 15 14 9 +]]> + + + We can work with 64-bit big integers: + + + x = sum(b .* (uint64(2).^(0:61))) + x = + 4154509482123930814 + +--> r = bitcmp(x) + r = + 14292234591585620801 + +--> bg = bitget(r, 1:62); +--> [msprintf("%d ",b(:)) ; msprintf("%d ",bg(:))] + ans = + "0 1 1 1 1 1 0 1 0 0 1 1 0 1 0 0 ... 1 0 0 0 0 1 0 0 1 1 1 1 1 0 0 1 0 1 1 0 0 1 1 1 " + "1 0 0 0 0 0 1 0 1 1 0 0 1 0 1 1 ... 0 1 1 1 1 0 1 1 0 0 0 0 0 1 1 0 1 0 0 1 1 0 0 0 " +]]> + + + bitnum can be an array: + + + bitcmp([0 0 0 0 0], 3:7) + ans = + 7. 15. 31. 63. 127. +]]> + + + bitnum can be > 52: + + + bitcmp(2^70, 65) + ans = + 36893488147419095040. + +--> sum(2.^(13:64)) + ans = + 36893488147419095040. +]]> + + + Huge decimal numbers can be processed: + + + log2(1e100) + ans = + 332.19280948873625903 + +--> r = bitcmp(1e100, 333) + r = + 7.498005798264093D+99 + +--> bitcmp(1e100) // bitnum = int(log2(x)) + 1 is used by default + ans = + 7.498005798264093D+99 + +--> bitcmp(r, 333) + ans = + 1.00000000000000D+100 +]]> + + + See Also + + + bitxor + + + bitget + + + minus + + + + + History + + + 6.1.1 + + + + Extension to 64 bit integers. + + + Extension to all signed integers. + + + Decimal positive integers > 2^52 up to 2^1024 = number_properties("huge") + can now be processed, with bitnum up to 1024 instead of 52. + + + bitnum is now optional as well for input decimal integers. + It can actually be an array. + + + + +