bit

Algorithm for bit expansion/duplication?

假装没事ソ 提交于 2020-01-01 09:55:22
问题 Is there an efficient (fast) algorithm that will perform bit expansion/duplication? For example, expand each bit in an 8bit value by 3 (creating a 24bit value): 1101 0101 => 11111100 01110001 11000111 The brute force method that has been proposed is to create a lookup table. In the future, the expansion value may need to be variable. That is, in the above example we are expanding by 3 but may need to expand by some other value(s). This would require multiple lookup tables that I'd like to

Fastest way to count number of bit transitions in an unsigned int

╄→尐↘猪︶ㄣ 提交于 2020-01-01 03:15:28
问题 I'm looking for the fastest way of counting the number of bit transitions in an unsigned int . If the int contains: 0b00000000000000000000000000001010 The number of transitions are: 4 If the int contains: 0b00000000000000000000000000001001 The number of transitions are: 3 Language is C. 回答1: int numTransitions(int a) { int b = a >> 1; // sign-extending shift properly counts bits at the ends int c = a ^ b; // xor marks bits that are not the same as their neighbors on the left return CountBits

bit,byte,word ,数据类型存储空间

∥☆過路亽.° 提交于 2020-01-01 00:24:24
位 bit 字节 byte 字 word : 不同计算机系统中占据一个单独的地址(内存单元的编号)并作为一个单元(由一个或多个字节组合而成)处理的一组二进制数。8位的CPU字长为8位,一个字等于一个字节,一次只能处理一个字节,而32位的CPU字长为32位,一个字等于4个字节,一次就能处理4个字节,同理字长为64位的CPU一次可以处理8个字节,一个字等于8个字节。 1字节=8位 (1 byte = 8bit) 1字=2字节 (1 word = 2 byte) 1 Byte = 8 Bits ; 1 KB = 1024 Bytes ; 1 MB = 1024 KB ; 1 GB = 1024 MB usb2.0标准接口传输速率。许多人都将“480mbps”误解为480兆/秒。其实,这是错误的,事实上“480mbps”应为“480兆比特/秒”或“480兆位/秒”,它等于“60兆字节/秒”,大家看到差距了吧。 字母占一个字节(byte), 汉字一般占用两个字节(byte) 数据类型存储空间和值的范围 C标准里面没有具体规定各种类型数据所占用存储单元的长度,这是由各编译系统自行决定的。 类型 字节数 取值范围 int (基本整型) 2 -32768~32767,即-2^15 ~ ( 2^15 - 1) 4 -2147483648 ~ 2147483647 ,即 -2^31 ~ ( 2^31

Unpack by bits in PHP

試著忘記壹切 提交于 2019-12-31 04:09:08
问题 I want to unpack a binary string into into an array by a weird sequence of 8-8-8-7 bits. I could easily do something like this, for a normal 8-8-8-8 sequence: $b=unpack('C*',$data); for ($i=0,$count=sizeof($b); $i < $count; $i+=4) { $out[]=array($b[$i+1],$b[$i+2],$b[$i+3],$b[$i+4]); } That would give me a 2D array of bytes, grouped by 4. But as the fourth being 7 bits, I just can't think of anything appropriate. Have you got some ideas? 回答1: Not sure if I completely understand, but if you

Filling an octet string

自作多情 提交于 2019-12-31 03:58:04
问题 I have 65 parameters of different bit length which I need to fill in an octet string. Parametrs would be filled continuously in octet string. For example, suppose the first parameter is 1 bit long so it would be filled at 0th bit position of 1st octet of the octet string. Now the second parameter is suppose 9 bit long. So the first 7 bits of this parametr would be filled in the same octet and the next 2 bits should go to 0th and 1st bit position of next octet. Similarly other parameters would

Retrieving a bit column from sql database in VB NET

喜你入骨 提交于 2019-12-31 02:49:29
问题 I have encountered a problem where in my database I have a column that is a bit either 0 or 1 specifying if a user is an admin or is account suspended or not. And in my VB code I am trying to retrieve that bit. Example code: Dim dtRequests As DataTable dtRequests = New DataTable("Users") dtRequests.Columns.Add("SESLoginID", System.Type.GetType("System.Int32")) dtRequests.Columns.Add("fullname", System.Type.GetType("System.String")) dtRequests.Columns.Add("SESSuspended", System.Type.GetType(

LeetCode解题报告—— 1-bit and 2-bit Characters & 132 Pattern & 3Sum

江枫思渺然 提交于 2019-12-30 22:54:37
1. 1-bit and 2-bit Characters We have two special characters. The first character can be represented by one bit 0 . The second character can be represented by two bits ( 10 or 11 ). Now given a string represented by several bits. Return whether the last character must be a one-bit character or not. The given string will always end with a zero. Example 1: Input: bits = [1, 0, 0] Output: True Explanation: The only way to decode it is two-bit character and one-bit character. So the last character is one-bit character. Example 2: Input: bits = [1, 1, 1, 0] Output: False Explanation: The only way

Swift Bit array to Bytes array (UInt8 array)

半城伤御伤魂 提交于 2019-12-30 06:46:21
问题 I have array with bits: var bits: [Bit] and how could I convert it to bytes array: var bytes: [UInt8] For example I have 280 bits and I should have 35 UInt8 in bytes array. I can think of solution where I take 8bits and check if first is true, if second is true and so and sum the results and have value. This I would do for every 8bits in my bits array. But I think this would be bad solution (it would work but with unnecessary calculations). I think there could be faster solution with some

Swift Bit array to Bytes array (UInt8 array)

…衆ロ難τιáo~ 提交于 2019-12-30 06:45:52
问题 I have array with bits: var bits: [Bit] and how could I convert it to bytes array: var bytes: [UInt8] For example I have 280 bits and I should have 35 UInt8 in bytes array. I can think of solution where I take 8bits and check if first is true, if second is true and so and sum the results and have value. This I would do for every 8bits in my bits array. But I think this would be bad solution (it would work but with unnecessary calculations). I think there could be faster solution with some

Python - check if a system is 32 or 64 bit to determine whether to run the function or not? [duplicate]

人走茶凉 提交于 2019-12-30 03:10:08
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: How do I determine if my python shell is executing in 32bit or 64bit mode? I made a question earlier that never got replied to, but I have something more specific now so hopefully you can help. Basically the SendKeys library only appears to install on my 32 bit system of Windows... So I was wondering if there is a way of making it so this function I am going to write will only execute on a 32 bit system? I