bit

How to convert string into bits and then into int array - java

冷暖自知 提交于 2019-12-07 05:39:50
问题 How to convert string into bits(not bytes) or array of bits in Java(i will do some operations later) and how to convert into array of ints(every 32 bits turn into the int and then put it into the array? I have never done this kind of conversion in Java. String->array of bits->(some operations I'll handle them)->array of ints 回答1: ByteBuffer bytes = ByteBuffer.wrap(string.getBytes(charset)); // you must specify a charset IntBuffer ints = bytes.asIntBuffer(); int numInts = ints.remaining(); int

Removing bit at specific index

喜欢而已 提交于 2019-12-07 01:13:54
问题 I'm basically trying to remove a bit from an integer at a specific index. That is, I do not want to unset/clear the bit; I actually want to strip it, so that every higher bit moves down, replacing the respective bit at its position. Visually, this could be compared to deleting an element from an array or removing a character from a string. For the sake of clarity, some examples: 1011011 (original number) ^ index = 2 0101111 (result) 10000000000000000000000000000001 ^ index = 31

Bit parity code for odd number of bits

不羁岁月 提交于 2019-12-07 00:28:10
问题 I am trying to find the parity of a bitstring so that it returns 1 if x has an odd # of 0's. I can only use basic bitwise operations and what I have so far passes most of the tests, but I'm wondering 2 things: Why does x ^ (x + ~1) work? I stumbled upon this, but it seems to give you 1 if there are an odd number of bits and something else if even. Like 7^6 = 1 because 7 = 0b0111 Is this the right direction of problem solving for this? I'm assuming my problem is stemming from the first

How does Java calculate negative numbers?

北战南征 提交于 2019-12-06 18:53:40
问题 I use the ~ operation for bit manipulation, and I'm just wondering how Java calculates the negative number? I checked the Java documentation: "The unary bitwise complement operator "~" inverts a bit pattern; it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0". For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111"." So if int a = 60 (0011 1100) , then int c = ~a (1100

SpringBoot 2.x 整合Lombok

时间秒杀一切 提交于 2019-12-06 16:40:59
Lombok的官方介绍 Project Lombok is a java library that automatically plugs into your editor and build tools, spicing up your java. Lombok以简单的注解形式来简化java代码,提高开发人员的开发效率 lombok 是一个编译级别的插件,它可以在项目编译的时候生成一些代码 1.为IntelliJ IDEA安装插件 file——>settings——>Plugins 安装完后需要重启IntelliJ IDEA 2.添加依赖 <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson<

PKUWC&SC 2018 刷题记录

安稳与你 提交于 2019-12-06 16:15:18
PKUWC&SC 2018 刷题记录 minimax 线段树合并的题,似乎并不依赖于二叉树。 之前写的草率的题解在这里: PKUWC2018 minimax Slay the Spire 注意到强化牌的强化倍数都是大于 \(1\) 的正整数,所以可以发现能强化就尽量强化。 用 \(F(x,y)\) 表示强化牌抽 \(x\) 张打出 \(y\) 张的倍率之和 用 \(G(x,y)\) 表示攻击牌抽 \(x\) 张打出 \(y\) 张的攻击之和 那么我们枚举抽了多少张攻击牌,在利用以上两个函数就可以算出答案了。 至于怎么计算那两个函数就看代码把。 #include<bits/stdc++.h> #define rep(i,l,r) for(int i=l;i<=r;i++) using namespace std; const int sz=3e3+7; const int mod=998244353; int T; int ans; int n,m,k; int a[sz],b[sz]; int inv[sz],fac[sz],ifac[sz]; int sum[sz],f[sz][sz],g[sz][sz]; void init(){ fac[0]=ifac[0]=1; fac[1]=ifac[1]=inv[1]=1; for(int i=2;i<sz;i++){ inv[i]

《Glibc内存管理》笔记DAY5

谁都会走 提交于 2019-12-06 15:07:34
分箱式内存管理 Unsorted bin   Unsorted bin 可以看作是 small bins 和 large bins 的 cache,只有一个 unsorted bin,以双向链表管理空闲 chunk,空闲 chunk 不排序,所有的 chunk 在回收时都要先放到 unsorted bin 中,分配时,如果在 unsorted bin 中没有合适的 chunk,就会把 unsorted bin 中的所有 chunk 分别加入到所属的 bin 中,然后再在 bin 中分配合适的 chunk。Bins 数组中的元素 bin[1]用于存储 unsorted bin 的 chunk 链表头。 /* The otherwise unindexable 1-bin is used to hold unsorted chunks. */ #define unsorted_chunks(M) (bin_at(M, 1)) /* Conveniently, the unsorted bin can be used as dummy top on first call */ #define initial_top(M) (unsorted_chunks(M)) unsorted_chunks(M):把 bin[1]设置为 unsorted bin 的 chunk 链表头。

java encoding

﹥>﹥吖頭↗ 提交于 2019-12-06 14:42:11
Supported Encodings The java.io.InputStreamReader , java.io.OutputStreamWriter , java.lang.String classes, and classes in the java.nio.charset package can convert between Unicode and a number of other character encodings. The supported encodings vary between different implementations of Java SE 8. The class description for java.nio.charset.Charset lists the encodings that any implementation of Java SE 8 is required to support. JDK 8 for all platforms (Solaris, Linux, and Microsoft Windows) and JRE 8 for Solaris and Linux support all encodings shown on this page. JRE 8 for Microsoft Windows may

Using Unsigned int 32 bit in Java? [duplicate]

家住魔仙堡 提交于 2019-12-06 13:57:46
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Converting 32-bit unsigned integer (big endian) to long and back I want to translate this expression in Java char tab[100]; tab[10] = '\xc0'; tab[48] = '\x80'; uint32_t w = 0x67452301; uint32_t x = 0xefcdab89; uint32_t y = 0x98badcfe; uint32_t z = 0x10325476; a = ((b & c) | (~b & d)) + (*(uint32_t*)(tab+0x00)) + a - 0x28955B88; a = ((a << 0x07) | (a >> 0x19)) + b; I'have tried this but... char[] tab = new char

多属性、多分类MySQL模式设计

廉价感情. 提交于 2019-12-06 13:49:50
一、导读 这是来自B乎的一个问答。 当数据同时具备多个属性/分类时,改如何设计表结构和查询? 二、需求描述 我偶尔也会逛逛B乎,看到一些感兴趣的话题也会回复下。 有一次,看到这样的一个话题: 链接: https://www.zhihu.com/questio... [mysql] 当数据同时属于多个分类时,该怎么查询? 分类cate字段为[1,2,3,4,5] ,假如要查询满足分类’2’和’5′ 的数据该怎么查询? 我尝试过用 cate like ‘%2%’ AND cate like ‘%5%’去查。 想问有没有更好的办法,我这样写数据少了还好,多了根本没法查,效率太低了。 恰好我以前做过类似的业务需求设计,所以就回复了这个问题。 三、模式设计思路 这个需求可以有几种不同的解决思路,我们分别展开说一下。 (一)用bit数据类型 大概思路如下: 1、物品属性列c1 用bit数据类型 来表示,也就是只有0、1两种取值 2、当物品属性具备某个分类属性时,其值为1,否则为0 3、假如共有5个分类,当物品拥有全部分类属性时,则其值为11111,若其不具备第3个分类属性,则其值为11011,在数据库中转成十进制存储 4、上述两种情况下,将二进制转换成十进制表示,即分别是31和27 [root@yejr.me] [zhishutang]> select conv(11111, 2, 10),