bit

STM32位带操作

早过忘川 提交于 2019-12-03 21:02:48
1.位带介绍   1)位带操作 在学习51单片机时就已经使用过位操作,比如使用sbit对单 片机IO口的定义,但是STM32中并没有这类关键字,而是通 过访问位带别名区来实现,即通过将每    个比特位膨胀成一个32位字,当访问这些字的时候就达到了访问比特的目的。 比方说BSRR寄存器有32个位,那么可以映射到32个地址上,当我们去访问这32个地址就达  到访问32个比特的目的。 (2)STM32位带及位带别名区域 支持位带操作的区域是 SRAM 区的最低 1MB 范围(APB1/2 ,AHB外设)和片内外设区的最低 1MB范围。 2.位带区与位带别名区地址转换 外设位带区与外设位带别名区的地址转换公式: AliasAddr = 0x42000000+ (A-0x40000000)*8*4 +n*4 SRAM位带区与SRAM位带别名区的地址转换公式: AliasAddr = 0x22000000+ (A-0x20000000)*8*4 +n*4 A:表示我们要操作的那个位所在的寄存器的地址 n:位序号 理解要点:位带区的一个位在位带别名区会被膨胀成四个字节 根据上述两个公式特点,将其统一为一个公式表示: ((A & 0xF0000000)+0x02000000+((A &0x000FFFFF)<<5)+(n<<2)) A:要操作的位所在寄存器的地址 n:位号,即在寄存器的第几位。

11/6 <bit manipulation>

妖精的绣舞 提交于 2019-12-03 20:33:05
389. Find the Difference ^ (按位异或): 参加运算的两个数,如果两个相应位为“异”(值不同),则该位结果为1,否则为0。 抵消掉相同的位,剩下的就是多余的位。 class Solution { public char findTheDifference(String s, String t) { char c = t.charAt(t.length() - 1); for(int i = 0; i < s.length(); i++){ c ^= s.charAt(i); c ^= t.charAt(i); } return c; } } 318. Maximum Product of Word Lengths value[i] |= 1 << (tmp.charAt(j) - 'a'); int大小为32位,全部只有26个小写字母,每一位表示一个字母。 &(按位与) :对应位均为1时,结果位为1,否则为0 | (按位或):参加运算的两个数只要两个数中的一个为1,结果就为1 class Solution { public int maxProduct(String[] words) { if(words == null || words.length == 0) return 0; int len = words.length; int[] value

Jenkins returned status code 128

本秂侑毒 提交于 2019-12-03 17:43:25
问题 I am trying to setup Jenkins with BitBucket GIT repository, but the Jenkins console always gives me this error code: Started by user Dakado Building in workspace /var/lib/jenkins/workspace/TEST852 Fetching changes from the remote Git repository Fetching upstream changes from git://bitbucket.org/GameTeamCZ/gtplaytime.git FATAL: Failed to fetch from git://bitbucket.org/GameTeamCZ/gtplaytime.git hudson.plugins.git.GitException: Failed to fetch from git://bitbucket.org/GameTeamCZ/ gtplaytime.git

Naudio - Convert 32 bit wav to 16 bit wav

末鹿安然 提交于 2019-12-03 17:06:25
I've been trying to convert a 32 bit stereo wav to 16 bit mono wav. I use naudio to capture the sound I and thought that using just the two of four more significant bytes will work. Here is the DataAvailable implementation: void _waveIn_DataAvailable(object sender, WaveInEventArgs e) { byte[] newArray = new byte[e.BytesRecorded / 2]; short two; for (int i = 0, j = 0; i < e.BytesRecorded; i = i + 4, j = j + 2) { two = (short)BitConverter.ToInt16(e.Buffer, i + 2); newArray[j] = (byte)(two & 0xFF); newArray[j + 1] = (byte)((two >> 8) & 0xFF); } //do something with the new array: } Any help would

What is the most efficient way in Java to pack bits into byte[] and read it back?

被刻印的时光 ゝ 提交于 2019-12-03 17:03:27
问题 I currently use these two functions to pack and read bits in a byte array. Wondering if anybody has any better ideas or faster ways to do it? Edited the program with a few more optimization and tabled a few calculations. Currently 100mil Put and Get takes about 12 secs instead of 16 secs now. If anybody is using the current code make sure the value passed in to Put is a positive number as it's expecting unsigned numbers coming down. If there is interest I can put up signed and unsigned

Extract n most significant non-zero bits from int in C++ without loops

。_饼干妹妹 提交于 2019-12-03 15:37:39
I want to extract the n most significant bits from an integer in C++ and convert those n bits to an integer. For example int a=1200; // its binary representation within 32 bit word-size is // 00000000000000000000010010110000 Now I want to extract the 4 most significant digits from that representation, i.e. 1111 00000000000000000000010010110000 ^^^^ and convert them again to an integer (1001 in decimal = 9). How is possible with a simple c++ function without loops? Mike Seymour Some processors have an instruction to count the leading binary zeros of an integer, and some compilers have

How can I access a specific group of bits from a variable?

拟墨画扇 提交于 2019-12-03 13:01:50
问题 I have a variable with "x" number of bits. How can I extract a specific group of bits and then work on them in C? 回答1: You would do this with a series of 2 bitwise logical operations. [[Terminology MSB (msb) is the most-significant-bit; LSB (lsb) is the least-significant-bit. Assume bits are numbered from lsb==0 to some msb (e.g. 31 on a 32-bit machine). The value of the bit position i represents the coefficient of the 2^i component of the integer.]] For example if you have int x , and you

高精度模板 支持各种运算 c++

江枫思渺然 提交于 2019-12-03 12:23:32
绪言 自从有了高精度模板,妈妈再也不用怕我不会打高精度了! 代码 代码长度与日俱增啊~~~ 1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<cmath> 5 using namespace std; 6 7 bool insigma(char ch){ 8 return ch=='-'||('0'<=ch&&ch<='9'); 9 } 10 11 const int maxn = 1000; 12 struct number{ 13 int num[maxn]; 14 int len; 15 bool fu; 16 17 number(){//初始化 18 len=fu=0; 19 memset(num,0,sizeof(num)); 20 } 21 22 int updata_len(){//更新长度 23 for(int i=maxn-1;i>=0;i--) if(num[i]) return len=i+1; 24 return len=0; 25 } 26 27 // /* 28 number operator= (int x){//隐式转换 29 fu=(x<0); 30 num[0]=abs(x); 31 if(x>9) carry_bit(); 32 if(x<-9)

分库分表之后,id 主键如何处理

微笑、不失礼 提交于 2019-12-03 10:38:30
基于数据库的实现方案 数据库自增 id 这个就是说你的系统里每次得到一个 id,都是往一个库的一个表里插入一条没什么业务含义的数据,然后获取一个数据库自增的一个 id。拿到这个 id 之后再往对应的分库分表里去写入。 这个方案的好处就是方便简单,谁都会用;缺点就是单库生成自增 id,要是高并发的话,就会有瓶颈的;如果你硬是要改进一下,那么就专门开一个服务出来,这个服务每次就拿到当前 id 最大值,然后自己递增几个 id,一次性返回一批 id,然后再把当前最大 id 值修改成递增几个 id 之后的一个值;但是无论如何都是基于单个数据库。 适合的场景:你分库分表就俩原因,要不就是单库并发太高,要不就是单库数据量太大;除非是你并发不高,但是数据量太大导致的分库分表扩容,你可以用这个方案,因为可能每秒最高并发最多就几百,那么就走单独的一个库和表生成自增主键即可。 设置数据库 sequence 或者表自增字段步长 可以通过设置数据库 sequence 或者表的自增字段步长来进行水平伸缩。 比如说,现在有 8 个服务节点,每个服务节点使用一个 sequence 功能来产生 ID,每个 sequence 的起始 ID 不同,并且依次递增,步长都是 8。 适合的场景:在用户防止产生的 ID 重复时,这种方案实现起来比较简单,也能达到性能目标。但是服务节点固定,步长也固定,将来如果还要增加服务节点

Convert 12-bit Bayer image to 8-bit RGB using OpenCV

匿名 (未验证) 提交于 2019-12-03 10:24:21
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to use OpenCV 2.3.1 to convert a 12-bit Bayer image to an 8-bit RGB image. This seems like it should be fairly straightforward using the cvCvtColor function, but the function throws an exception when I call it with this code: int cvType = CV_MAKETYPE(CV_16U, 1); cv::Mat bayerSource(height, width, cvType, sourceBuffer); cv::Mat rgbDest(height, width, CV_8UC3); cvCvtColor(&bayerSource, &rgbDest, CV_BayerBG2RGB); I thought that I was running past the end of sourceBuffer, since the input data is 12-bit, and I had to pass in a 16-bit