search
Homephp教程php手册这样用01串,用01串

这样用01串,用01串

Jun 13, 2016 am 09:07 AM
thingseveralpointDiscoverandplaceuseof

这样用01串,用01串

  今天在做东西的时候,发现了几个挺有意思的地方,记下来和大家分享分享。从几个小问题开始

记录一个年龄段你会怎么记录,能表达类似“50~70”之类的就可以?

  也许你会说很简单啊,用两个字段,一个start=>开始年龄、一个end=>结束年龄,更或者在一个字段中,使用start|end这样的格式,中间用一个非数字隔开,或者用start|start-end,哈哈,反正方法很多,但是这时候如果要求升级,要你表示10~20、25、29~40这些年龄,你要怎么表示呢?当然还可以通过字符串去表示比如:10-20|25|29-40,自己定一些规则去表示,但是这个表示方法还可以优化吗,答案是肯定的。

  可以用01字符串去表示不重复的年龄区间,默认是100个0,标志1~100岁的位置,如果为1则表示有该年龄,为零则表示没有该年龄。为了好说明,这里使用10个零,表示1~10岁,那么:

<p>0111111000    =>  表示2~7岁</p>
<p>0110111010    => 表示2~3、5~7、9岁</p>

  哈哈,是不是很方便就可以表示了,而且很容易理解,当然了,这样也有他的缺点,这样表示起来很方便,但是用起来确不方便,需要去计算。

从1、2、3、......、199、200里面随机选些数,怎么表示?

  当然了,这个方法有很多种,比如说用字符串表示,每个数字之间用非数字分割,像这样:1|5|100|199。我想说的这种还是用01串表示,就像上面的1~200,选取其中的一部分这个问题,我可以使用200个位置的字符串,每个位置是0或者1,每个位置放好是它对应的数字,这样的话,就又将这些信息表示为01字符串了。还是按照0~10举个例子

<p>0111111000    =>  表示2、3、4、5、6、7</p>
<p>0110111010    => 表示2、3、5、6、7、9</p>

  当然了有人可能会说了,我想表示的数据不是连续的,比如说我想表示

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

  上面这些数有的很大有的很小,没有规律,我们要表示总体不超过10个的数不会去用他们中最大的个数个位置吧(比如说这里19658个0),当然不会,这种情况可以使用映射,映射关系如下:

<span>1</span> => <span>1926</span><span>,
</span><span>2</span> => <span>19658</span><span>,
</span><span>3</span> => <span>12</span><span>,
</span><span>4</span> => <span>5638</span><span>,
</span><span>5</span> => <span>8975</span><span>,
</span><span>6</span> => <span>965</span><span>,
</span><span>7</span> => <span>369</span><span>,
</span><span>8</span> => <span>5126</span><span>,
</span><span>9</span> => <span>5698</span><span>,
</span><span>10</span> => <span>14556</span>

  这个时候要想表示1926、12、5698这几个选中的情况的时候,可以使用下面的01串:

  1010000010

  也许你也发现了,这个还可以起到节省流量的效果,我们在双方交互的时候,把映射关系建立好,网络传递的时候不需要传递真实的数据,只需要传递对应的01串就行。

  当然了,这个还可以表示很多东西,比如说我把一天的时间没5分钟分为1段,一共有288段,这个时候从这里面随机选取一些个5分钟段,用288个自己长度的01串来表示这个是不是挺好的,哈哈。

  在某种情况下这种01串表示的方式还是挺可取的,有时候会起到节省流量的效果。

 

  本文版权归作者iforever(luluyrt@163.com)所有,未经作者本人同意禁止任何形式的转载,转载文章之后必须在文章页面明显位置给出作者和原文连接。

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.