Prototype:
unsigned int getbitsvalue (unsigned int input, unsigned int startbit, unsigned int bitlen)
Input parameters:
Integer entered by input
Startbit need to get the start bit
Bitlen the bit length to get
Output parameters (the memory area pointed to by the pointer is guaranteed to be valid):
No
return value:
The corresponding bit value
Example:
Input: 4, 2, 2
Returns: 2
4 The corresponding binary is 1 (bit0 and bit1 are 0,bit2), then 2 bits starting from Bit2 are 10, then the corresponding decimal is 2.
#include <stdlib.h> #include <string.h> #include "oj.h"/* Function: input: Pintarray: Array, ncout: array length output: return: Returns the maximum value */int getsubarraysum (int* pintarray, int ncount) {/ * here implements the function */ int thissum,maxsum,j; Thissum = Maxsum =0; for (j = 0;j < ncount;j++) { thissum + = pintarray[j]; if (Thissum > Maxsum) maxsum = thissum; else if (Thissum < 0) thissum = 0; } return maxsum; }</span>
Algorithm ideas:
Using integers to convert to 2, the number is first stored in an array, and then the specified number of digits is read out.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Takes the specified length of data from the specified bit bit of a given positive integer