Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3636026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T00:58:42+00:00 2026-05-19T00:58:42+00:00

I found some interesting bit twiddling in source\common\unicode\utf.h file of ICU library (International Components

  • 0

I found some interesting bit twiddling in "source\common\unicode\utf.h" file of ICU library (International Components for Unicode). The bit twiddling is intended for checking whether a number is in a particular range.

// Is a code point in a range of U+d800..U+dbff?
#define U_IS_LEAD(c) (((c)&0xfffffc00)==0xd800)

I have figured out the magic number (0xfffffc00) come from:

MagicNumber = 0xffffffff - (HighBound - LowBound)

However, I also found that the formula doesn’t apply to every arbitrary range. Does somebody here know in what circumstance the formula works?

Is there another bit twiddling for checking whether a number is in particular range?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T00:58:42+00:00Added an answer on May 19, 2026 at 12:58 am

    For these tricks to apply, the numbers must have some common features in their binary representation.

    0xD800 == 0b1101_1000_0000_0000
    0xDBFF == 0b1101_1011_1111_1111
    

    What this test really does is to mask out the lower ten bits. This is usually written as

    onlyHighBits = x & ~0x03FF
    

    After this operation (“and not”) the lower ten bits of onlyHighBits are guaranteed to be zero. That means that if this number equals the lower range of the interval now, it has been somewhere in the interval before.

    This trick works in all cases where the lower and the higher limit of the interval start with the same digits in binary, and at some point the lower limit has only zeroes while the higher limit has only ones. In your example this is at the tenth position from the right.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Opened a LinkedHashSet source code today and found some interesting thing: public class LinkedHashSet<E>
Some days ago I looked at boost sources and found interesting typedef . There
I'm doing some research into using log4net, and I found the IObjectRenderer interface interesting.
I'm doing some ASP.NET development in VS and have just found an interesting little
I just found an interesting problem between translating some data: VB.NET: CByte(4) << 8
In this thread I found some interesting moment, If class uses only as superclass
I found some interesting code when I was looking at things that people had
I found some interesting possibility in many regex engines: It's possible to place backreference
I stumbled across this article and found it very interesting, so I ran some
comrades) I've found some interesting behavior of Invalidate method in multithreaded applications. I hope

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.