bit

Bit fields in C#

匿名 (未验证) 提交于 2019-12-03 08:28:06
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have a structure which I need to populate and write to disk (several actually). An example is: byte-6 bit0 - original_or_copy bit1 - copyright bit2 - data_alignment_indicator bit3 - PES_priority bit4-bit5 - PES_scrambling control. bit6-bit7 - reserved In C I might do something like the following: struct PESHeader { unsigned reserved:2; unsigned scrambling_control:2; unsigned priority:1; unsigned data_alignment_indicator:1; unsigned copyright:1; unsigned original_or_copy:1; }; Is there any way to do this in C# that would enable me to access

Bit manipulations good practices

独自空忆成欢 提交于 2019-12-03 08:12:11
问题 As a beginner C programmer, I am wondering, what would be the best easy-to-read and easy-to-understand solution for setting control bits in a device. Are there any standards ? Any example code to mimic? Google didn't give any reliable answer. For example, I have a control block map: The first way I see would be to simply set the needed bits. It requires a bunch of explanations in comments and seems to be not all that professional. DMA_base_ptr[DMA_CONTROL_OFFS] = 0b10001100; The second way I

Can a public key have a different length (encryption) than the private key?

我与影子孤独终老i 提交于 2019-12-03 08:04:16
I have a 1024 bits private key, and use it to generate a public key. Does that automatically mean that my public key also has 1024 encryption? Or can it be of a lesser encryption size? (512, 256...) PS: What i'm mostly interested in, and talking about, is the size of the modulus ("n") in RSA keys. The size is typically 1024 or 2048 bits. But I'm glad to see that this sparked a discussion, and all this is feeding my interest in cryptography. No. The public key in a key pair always matches the private key size, in fact it is derived from the private key. However, with some public key

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

与世无争的帅哥 提交于 2019-12-03 07:51:11
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. 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(c); // count number of set bits in c } For an efficient implementation of CountBits see http://graphics

Detect CPU Architecture (32-bit / 64-bit) runtime in Objective C (Mac OS X)

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm currently wring a Cocoa application which needs to execute some (console) applications which are optimized for 32 and 64 bit. Because of this I would like to detect what CPU architecture the application is running on so I can start the correct console application. So in short: how do I detect if the application is running on a 64 bit OS? Edit: I know about the Mach-O fat binaries, that was not my question. I need to know this so I can start another non bundled (console) application. One that is optimized for x86 and one for x64 . 回答1:

how to extract byte data from bluetooth heart rate monitor in objective c

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Im having trouble understanding bytes and uint8_t values. I am using the sample project created by apple that reads data from a Bluetooth 4.0 heart rate monitor via the heart rate service protocol. THe sample project gives out heart rate data as below: - ( void ) updateWithHRMData :( NSData *) data { const uint8_t * reportData = [ data bytes ]; uint16_t bpm = 0 ; if (( reportData [ 0 ] & 0x01 ) == 0 ) { /* uint8 bpm */ bpm = reportData [ 1 ]; } else { /* uint16 bpm */ bpm = CFSwapInt16LittleToHost (*( uint16_t *)(& reportData [ 1 ]

matrix multiplication in swift using Accelerate framework 32 bit vs 64 bit

匿名 (未验证) 提交于 2019-12-03 07:50:05
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to do matrix multiplication in Swift using the Accelerate framework. Used the vDSP_mmulD. This worked perfectly in the iPhone6 , 6 plus, iPad Air simulator (all 64 bit architecture) but did not work with any of the 32 bit architecture devices. It sees like vDSP_mmulD is not recognized by the 32 bit architecture and the program does not build. Error message displayed is "use of unresolved identifier 'vDSP_mmulD'" Has anybody else seen this error? Please let me know your thoughts. I am using Xcode 6.1. Thanks. 回答1: Simple solution:

Can not find .so file on 64 bit android device

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Using aviary android sdk using android studio and gradle build. App generated running fine on all devices having 32 bit architecture. Same app is giving following error in the 64 bit device [Eg. Sony C4] java . lang . UnsatisfiedLinkError : dalvik . system . PathClassLoader [ DexPathList [[ zip file "/data/app/com.myapp/base.apk" ], nativeLibraryDirectories =[ /data/ app / com . myapp / lib / arm64 , /vendor/ lib64 , /system/ lib64 ]]] couldn 't find "libaviary_moalite.so" gredle.build part dependencies { ... compile 'com.android

Why ENOUGH is enough? (storing an int in a char array)

匿名 (未验证) 提交于 2019-12-03 07:36:14
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In one of the answers (and its comments) on How to convert an int to string in C the following solution is given char str[ENOUGH]; sprintf(str, "%d", 42); in the comments caf mentions that ENOUGH can be determined at compile time with: #define ENOUGH ((CHAR_BIT * sizeof(int) - 1) / 3 + 2) I get the + 2 because you need to be able to display the minus sign and null terminator but what is the logic behind the other part? Specifically CHAR_BIT ? 回答1: If int type is 32-bit, how many bytes do you need to represent any number (without sign and

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

可紊 提交于 2019-12-03 06:55:40
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 versions. class BitData { static void Put(byte Data[], final int BitOffset, int NumBits, final int Value) {