So with 01 strings, with 01 strings _php Tutorial

Source: Internet
Author: User

So with 01 strings, with 01 strings

Today, when doing something, found a few interesting places, write down to share with you. Start with a few small problems

How do you record an age, and you can express something like "50~70"?

Maybe you'll say it's easy. With two fields, a start=> start age, a end=> end age, or in a field, use a format such as Start|end, separated by a non-digit, or with start|start-end, haha, Anyway, a lot of methods, but this time if the request to upgrade, you want to show 10~20, 25, 29~40 these ages, how do you say? Of course, you can also use a string to express, such as: 10-20|25|29-40, you set some rules to express, but this expression can also be optimized, the answer is yes.

You can use 01 string to represent the age range of the non-repetition, the default is 100 0, the position of the flag 1~100岁, if 1 is the age, zero indicates that there is no age. For the sake of illustration, 10 zeros are used here, indicating 1~10岁, then:

0111111000 = 2~7岁

0110111010 = three, 5~7, 9

Haha, is not very convenient to express, and it is easy to understand, of course, this also has his shortcomings, so it is very convenient to express, but it is not convenient to use, to calculate.

From 1, 2, 3 、......、 199, 200 randomly selected number, how to say?

Of course, there are many kinds of methods, such as string representations, where each number is separated by a non-digit, like this: 1|5|100|199. I would like to say this or with 01 string, just like the above 1~200, select part of the problem, I can use 200 positions of the string, each position is 0 or 1, each position is the corresponding number, so that the information is expressed as a 01 string. or follow 0~10 for an example.

0111111000 = 2, 3, 4, 5, 6, 7

0110111010 = 2, 3, 5, 6, 7, 9

Of course, someone might say, I want to show the data is not continuous, for example, I want to express

1926, 19658, 12, 5638, 8975, 965, 369, 5126, 5698, 14556

Some of these numbers are very small, there is no regularity, we want to say that the total number of not more than 10 is not going to use their largest number of places (for example, here 19,658 0), of course, this can use the mapping, the mapping relationship is as follows:

1 1926 , 2 19658 , 3  A , 4 5638 , 5 8975 , 6 965 , 7 369 , 8 5126 , 9 5698 , Ten 14556

This time to indicate 1926, 12, 5698 of these selected cases, you can use the following 01 strings:


Perhaps you also found that this can also play a saving effect, we in the interaction between the time, the mapping relationship is established, the network when the transmission of the time does not need to pass the real data, only need to pass the corresponding 01 strings on the line.

Of course, this can also represent a lot of things, for example, I put a day without 5 minutes divided into 1 segments, a total of 288 paragraphs, this time from here randomly selected some 5 minutes, with 288 of their own length of 01 string to indicate this is not very good, haha.

In some cases, this 01-string representation of the way is still quite desirable, and sometimes it will save the flow of the effect.

This copyright belongs to the author Iforever ( all, without the author's consent to prohibit any form of reprint, reprinted article must be in the article page obvious location to the author and the original text connection. true techarticle So with 01 strings, with 01 strings today in doing things, found a few interesting places, write down to share with you. Starting with a few small questions, how do you get to record an age ?

  • 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: 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.