这么用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岁,那么:
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进制

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

The message "Your organization has asked you to change your PIN" will appear on the login screen. This happens when the PIN expiration limit is reached on a computer using organization-based account settings, where they have control over personal devices. However, if you set up Windows using a personal account, the error message should ideally not appear. Although this is not always the case. Most users who encounter errors report using their personal accounts. Why does my organization ask me to change my PIN on Windows 11? It's possible that your account is associated with an organization, and your primary approach should be to verify this. Contacting your domain administrator can help! Additionally, misconfigured local policy settings or incorrect registry keys can cause errors. Right now

Windows 11 brings fresh and elegant design to the forefront; the modern interface allows you to personalize and change the finest details, such as window borders. In this guide, we'll discuss step-by-step instructions to help you create an environment that reflects your style in the Windows operating system. How to change window border settings? Press + to open the Settings app. WindowsI go to Personalization and click Color Settings. Color Change Window Borders Settings Window 11" Width="643" Height="500" > Find the Show accent color on title bar and window borders option, and toggle the switch next to it. To display accent colors on the Start menu and taskbar To display the theme color on the Start menu and taskbar, turn on Show theme on the Start menu and taskbar

By default, the title bar color on Windows 11 depends on the dark/light theme you choose. However, you can change it to any color you want. In this guide, we'll discuss step-by-step instructions for three ways to change it and personalize your desktop experience to make it visually appealing. Is it possible to change the title bar color of active and inactive windows? Yes, you can change the title bar color of active windows using the Settings app, or you can change the title bar color of inactive windows using Registry Editor. To learn these steps, go to the next section. How to change title bar color in Windows 11? 1. Using the Settings app press + to open the settings window. WindowsI go to "Personalization" and then

Do you see "A problem occurred" along with the "OOBELANGUAGE" statement on the Windows Installer page? The installation of Windows sometimes stops due to such errors. OOBE means out-of-the-box experience. As the error message indicates, this is an issue related to OOBE language selection. There is nothing to worry about, you can solve this problem with nifty registry editing from the OOBE screen itself. Quick Fix – 1. Click the “Retry” button at the bottom of the OOBE app. This will continue the process without further hiccups. 2. Use the power button to force shut down the system. After the system restarts, OOBE should continue. 3. Disconnect the system from the Internet. Complete all aspects of OOBE in offline mode

Taskbar thumbnails can be fun, but they can also be distracting or annoying. Considering how often you hover over this area, you may have inadvertently closed important windows a few times. Another disadvantage is that it uses more system resources, so if you've been looking for a way to be more resource efficient, we'll show you how to disable it. However, if your hardware specs can handle it and you like the preview, you can enable it. How to enable taskbar thumbnail preview in Windows 11? 1. Using the Settings app tap the key and click Settings. Windows click System and select About. Click Advanced system settings. Navigate to the Advanced tab and select Settings under Performance. Select "Visual Effects"

Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

We all have different preferences when it comes to display scaling on Windows 11. Some people like big icons, some like small icons. However, we all agree that having the right scaling is important. Poor font scaling or over-scaling of images can be a real productivity killer when working, so you need to know how to customize it to get the most out of your system's capabilities. Advantages of Custom Zoom: This is a useful feature for people who have difficulty reading text on the screen. It helps you see more on the screen at one time. You can create custom extension profiles that apply only to certain monitors and applications. Can help improve the performance of low-end hardware. It gives you more control over what's on your screen. How to use Windows 11

Screen brightness is an integral part of using modern computing devices, especially when you look at the screen for long periods of time. It helps you reduce eye strain, improve legibility, and view content easily and efficiently. However, depending on your settings, it can sometimes be difficult to manage brightness, especially on Windows 11 with the new UI changes. If you're having trouble adjusting brightness, here are all the ways to manage brightness on Windows 11. How to Change Brightness on Windows 11 [10 Ways Explained] Single monitor users can use the following methods to adjust brightness on Windows 11. This includes desktop systems using a single monitor as well as laptops. let's start. Method 1: Use the Action Center The Action Center is accessible
