parity

905. Sort Array By Parity

被刻印的时光 ゝ 提交于 2020-02-29 06:19:38
Question 905. Sort Array By Parity Solution 题目大意:数组排序,偶数放前,奇数在后,偶数的数之间不用管顺序,奇数的数之间也不用管顺序 思路:建两个list,一个放偶数,一个放奇数,最后将两个list合并,转化为数组返回 Java实现: public int[] sortArrayByParity(int[] A) { List<Integer> evenList = new ArrayList<>(); List<Integer> oddList = new ArrayList<>(); for (int i = 0; i < A.length; i++) { if (A[i] % 2 == 0) evenList.add(A[i]); else oddList.add(A[i]); } evenList.addAll(oddList); int[] retArr = new int[A.length]; for (int i = 0; i < evenList.size(); i++) { retArr[i] = evenList.get(i); } return retArr; } 来源: oschina 链接: https://my.oschina.net/u/159293/blog/2066188

992. Sort Array By Parity II

喜欢而已 提交于 2020-02-28 21:29:23
Question 992. Sort Array By Parity II Solution 题目大意:给一个int数组,一半是奇数一半是偶数,分别对偶数数和奇数数排序并要求这个数本身是偶数要放在偶数位上 思路:把奇数数和偶数数筛选出来后对其分别排序,再按奇偶索引放到原数组上 Java实现: public int[] sortArrayByParityII(int[] A) { List<Integer> oddList = new ArrayList<>(); List<Integer> evenList = new ArrayList<>(); for (int a : A) { if (a % 2 == 0) evenList.add(a); else oddList.add(a); } Collections.sort(oddList); Collections.sort(evenList); for (int i = 0; i < oddList.size(); i++) { A[2 * i] = evenList.get(i); A[2 * i + 1] = oddList.get(i); } return A; } 来源: oschina 链接: https://my.oschina.net/u/159293/blog/2246150

How to add even parity bit on 7-bit binary number

我怕爱的太早我们不能终老 提交于 2020-01-21 19:13:20
问题 I am continuing from my previous question. I am making a c# program where the user enters a 7-bit binary number and the computer prints out the number with an even parity bit to the right of the number. I am struggling. I have a code, but it says BitArray is a namespace but is used as a type. Also, is there a way I could improve the code and make it simpler? namespace BitArray { class Program { static void Main(string[] args) { Console.WriteLine("Please enter a 7-bit binary number:"); int a =

How can I calculate Longitudinal Redundancy Check (LRC)?

徘徊边缘 提交于 2019-12-31 01:51:07
问题 I've tried the example from wikipedia: http://en.wikipedia.org/wiki/Longitudinal_redundancy_check This is the code for lrc (C#): /// <summary> /// Longitudinal Redundancy Check (LRC) calculator for a byte array. /// ex) DATA (hex 6 bytes): 02 30 30 31 23 03 /// LRC (hex 1 byte ): EC /// </summary> public static byte calculateLRC(byte[] bytes) { byte LRC = 0x00; for (int i = 0; i < bytes.Length; i++) { LRC = (LRC + bytes[i]) & 0xFF; } return ((LRC ^ 0xFF) + 1) & 0xFF; } It said the result is

Strip parity bits in C from 8 bits of data followed by 1 parity bit

两盒软妹~` 提交于 2019-12-11 09:33:04
问题 I have a buffer of bits with 8 bits of data followed by 1 parity bit. This pattern repeats itself. The buffer is currently stored as an array of octets. Example (p are parity bits): 0001 0001 p000 0100 0p00 0001 00p01 1100 ... should become 0001 0001 0000 1000 0000 0100 0111 00 ... Basically, I need to strip of every ninth bit to just obtain the data bits. How can I achieve this? This is related to another question asked here sometime back. This is on a 32 bit machine so the solution to the

intel assembly TEST PF flag operation

最后都变了- 提交于 2019-12-11 07:16:08
问题 I'm was doing a manual operation with TEST (Parity flag operation) , the problem it's that i can't get the right result, consider this: ax = 256 = 0000 0001 0000 0000 so if i do: test ah, 0x44 the PF flag operation should be: 0000 0000 = 0000 0001 & 0100 0100 PF = 0000 0000 XNOR 0000 0000 PF = 1111 1111 ? I've followed the intel reference, according to this: the question it's what i'm doing wrong? 回答1: BitwiseXNOR is a horizontal XNOR of the bits, producing a single bit. Remember that PF is

9 bit protocol on UART in embedded Linux

北战南征 提交于 2019-12-10 10:31:58
问题 I am trying to force a 9-bit protocol on a UART in embedded Linux. Currently I am testing this out on the am335x_evm board. I am planning on doing this using stick parity. Ideally I was hoping I would not need to actually modify any of the code for the omap-serial.c driver. The reason for the 9-bit protocol is to support some legacy hardware that uses it. The parity bit needs to be 1 for the address portion of the message, 0 for the data portion, then 1 again for the termination byte. I was

Excel - Determine Parity of Permutation

杀马特。学长 韩版系。学妹 提交于 2019-12-08 01:06:36
问题 I am working on an Excel sheet where I need to determine the parity of a vertical array of numbers of size N . The array contains each number from 1 to N exactly one time each. In this context, parity is defined as how many swaps is necessary to convert the scrambled array to a sorted array from smallest to largest. For example, the array {3;1;2;4} has even parity because it would require two swaps (at minimum) to convert to {1;2;3;4} , but would always require an even number of swaps. See

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

适合区块链开发者使用的10个工具

谁说我不能喝 提交于 2019-12-06 23:22:15
本文翻译自DashMagazine《10 Tools for Blockchain Development》,原文链接: https://hackernoon.com/10-tools-for-blockchain-development-67f862a03a36 。有部分不影响原意的修改。 区块链虽然通过比特币等加密货币为大多数人所熟知,但它的用途远不止加密货币。很多世界知名的公司都在研究如何利用这项技术,比如摩根士丹利推出MPCoin、Facebook、Google等都推出了各自的区块链计划。国内如阿里巴巴、百度、腾讯等巨头也纷纷布局区块链。企业对区块链的兴趣自然会带来对区块链开发人员的需求。根据upwork的一份报告,区块链恰好是其平台上增长最快的技能,超过了TensorFlow和机器学习等技能,跻身前20名。 区块链不仅仅用于处理交易或存储价值,一些区块链能够执行智能合约,在其上开发应用程序(DApp)。如果你有志成为一名区块链开发者,或者想启动一个区块链项目,这里有10个区块链开发人员经常使用的工具推荐给你。当然,区块链开发工具有很多,这10个只是更受欢迎而已。 1、Solidity Solidity是以Contact为导向的编程语言,用于编写在各个区块链平台(如以太坊)上执行的智能合约。Solidity具有与JavaScript编程语言类似的语法,并增强了以太坊虚拟机