Linux Kernel Function fls (), Linux kernel function fls

Source: Internet
Author: User
Tags bit set

Linux Kernel Function fls (), Linux kernel function fls

Functions of Linux kernel functions fls ()

/*** Fls-find last (most-significant) bit set * @ x: the word to search ** This is defined the same way as ffs. * Note fls (0) = 0, fls (1) = 1, fls (0x80000000) = 32. */static _ always_inline int fls (int x) {int r = 32; if (! X) return 0; if (! (X & 0xffff0000u) {x <= 16; r-= 16;} if (! (X & 0xff000000u) {x <= 8; r-= 8;} if (! (X & 0xf0000000u) {x <= 4; r-= 4;} if (! (X & 0xc0000000u) {x <= 2; r-= 2;} if (! (X & 0x80000000u) {x <= 1; r-= 1;} return r ;}

Purpose: return the sequence number of the highest valid bit (from low to left) of the input parameter. This sequence number is different from the Starting sequence number of normal 0, it starts with 1 (0 is returned if there is no valid bit ).

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.