这样用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岁,那么:
0111111000 => 表示2~7岁
0110111010 => 表示2~3、5~7、9岁
哈哈,是不是很方便就可以表示了,而且很容易理解,当然了,这样也有他的缺点,这样表示起来很方便,但是用起来确不方便,需要去计算。
从1、2、3、......、199、200里面随机选些数,怎么表示?
当然了,这个方法有很多种,比如说用字符串表示,每个数字之间用非数字分割,像这样:1|5|100|199。我想说的这种还是用01串表示,就像上面的1~200,选取其中的一部分这个问题,我可以使用200个位置的字符串,每个位置是0或者1,每个位置放好是它对应的数字,这样的话,就又将这些信息表示为01字符串了。还是按照0~10举个例子
0111111000 => 表示2、3、4、5、6、7
0110111010 => 表示2、3、5、6、7、9
当然了有人可能会说了,我想表示的数据不是连续的,比如说我想表示
1926、19658、12、5638、8975、965、369、5126、5698、14556
上面这些数有的很大有的很小,没有规律,我们要表示总体不超过10个的数不会去用他们中最大的个数个位置吧(比如说这里19658个0),当然不会,这种情况可以使用映射,映射关系如下:
<span style="color: #800080;">1</span> => <span style="color: #800080;">1926</span><span style="color: #000000;">,</span><span style="color: #800080;">2</span> => <span style="color: #800080;">19658</span><span style="color: #000000;">,</span><span style="color: #800080;">3</span> => <span style="color: #800080;">12</span><span style="color: #000000;">,</span><span style="color: #800080;">4</span> => <span style="color: #800080;">5638</span><span style="color: #000000;">,</span><span style="color: #800080;">5</span> => <span style="color: #800080;">8975</span><span style="color: #000000;">,</span><span style="color: #800080;">6</span> => <span style="color: #800080;">965</span><span style="color: #000000;">,</span><span style="color: #800080;">7</span> => <span style="color: #800080;">369</span><span style="color: #000000;">,</span><span style="color: #800080;">8</span> => <span style="color: #800080;">5126</span><span style="color: #000000;">,</span><span style="color: #800080;">9</span> => <span style="color: #800080;">5698</span><span style="color: #000000;">,</span><span style="color: #800080;">10</span> => <span style="color: #800080;">14556</span>
这个时候要想表示1926、12、5698这几个选中的情况的时候,可以使用下面的01串:
1010000010
也许你也发现了,这个还可以起到节省流量的效果,我们在双方交互的时候,把映射关系建立好,网络传递的时候不需要传递真实的数据,只需要传递对应的01串就行。
当然了,这个还可以表示很多东西,比如说我把一天的时间没5分钟分为1段,一共有288段,这个时候从这里面随机选取一些个5分钟段,用288个自己长度的01串来表示这个是不是挺好的,哈哈。
在某种情况下这种01串表示的方式还是挺可取的,有时候会起到节省流量的效果。
本文版权归作者iforever([email protected])所有,未经作者本人同意禁止任何形式的转载,转载文章之后必须在文章页面明显位置给出作者和原文连接。
- 1楼NewSilen
- 再转成二进制,换算成十进制传送如何
- Re: 奔跑的Man
- @NewSilen,网络通信的时候还是要打包为2进制

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python each have their own advantages and are suitable for different scenarios. 1.PHP is suitable for web development and provides built-in web servers and rich function libraries. 2. Python is suitable for data science and machine learning, with concise syntax and a powerful standard library. When choosing, it should be decided based on project requirements.

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Dreamweaver CS6
Visual web development tools