Takes the specified length of data from the specified bit bit of a given positive integer

Source: Internet
Author: User

    • Interface description

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.