Differences or functions

Source: Internet
Author: User

1. Exchange the values of two integers without using the third parameter.
A = 9;
B = 11;

A = a ^ B; 1001 ^ 1011 = 0010
B = B ^ A; 1011 ^ 0010 = 1001
A = a ^ B; 0010 ^ 1001 = 1011

A = 11;
B = 9;

Ii. Parity Determination

^ The A operation is to divide each bit in a by bit to an exclusive or. For example, if a = 4'b1010, B = 1 ^ 0 ^ 1 ^ 0 = 0, therefore, it is a convenient operation to determine whether the number of digits in A is an odd or even number.

3. Gray Code)

Gray code was proposed by Frank gray of Bell's laboratory in 1940 to prevent errors when transmitting signals using the pusle code modulation method, and obtained a US patent in March 17, 1953. The gray code is a collection of numbers. There is only one dollar between two adjacent numbers, which is not authorized to be digital, and the gray code sequence is not unique.
Direct arrangement
The gray code with a binary value of 0 is the first item. The first item changes the rightmost bitwise element, and the second item changes the leftmost element of the first bitwise element with a value of 1 on the right, the third and fourth methods are the same as the first and second methods. In this way, the gray codes of N yuan can be arranged.

1. convert a natural binary code to a binary Gray Code
The principle of converting a natural binary code into a binary Gray code is to retain the highest bit of a natural binary code as the highest bit of the gray code, and the secondary high gray code is the highest bit of a binary code and the secondary high is different or, the rest of the gray code are similar to the secondary high.

2. Convert binary Gray code to natural binary code
To convert a binary Gray code to a natural binary code, the highest bit of the gray code is reserved as the highest bit of the natural binary code, the secondary high natural binary code is a high natural binary code that is different from the secondary high gray code, while the rest of the natural binary code are similar to the secondary high natural binary code.

Binary Number to Gray Code
(Assuming that the binary value is 0 as the gray code 0)
Gray Code N-bit = binary code N-bit (n + 1) + binary code N-bit. Do not bother with the hexadecimal notation.

Code: Gray = (Binary> 1) ^ binary; Gray code to binary number
The Nth bit of the binary code = the nth bit of the binary code (n + 1) + the nth bit of the gray code. Because the binary code and Gray Code both have the same digits, the binary code can be calculated from 0 on the left of the highest bit. Code: // ------ assume Reg [n-1] gray, binary; integer I; for (I = 0; I <= n-1; I = I + 1) binary [I] = ^ (gray> I) // After the gray shift, the bitwise XOR or put a piece of code, which is used for reference: /* logic to convert binary numbers into gray coded binary numbers is implemented in the following OpenGL code.
*/
ModuleBinary2gray ();
RegCLK;
RegRstn;
Reg[5:0] counter_binary, counter_binary_reg, counter_gray, counter_gray_reg;
IntegerCount, file_wr;

/* Initial block to generate clock and reset */
InitialBegin
CLK = 0; rstn
= 0; #100 rstn
= 1;
Forever Begin
#10 CLK
=! CLK;
 End End

/* Synchronous logic for registering the data and incrementing the counter for binary data */
Always@(PosedgeCLK
Or NegedgeRstn)
Begin
If(! Rstn)Begin
Counter_binary_reg <= 'b0;
Counter_gray_reg <= 'b0;End
Else Begin 
Counter_binary_reg <= counter_binary
+ 1;
Counter_gray_reg <= counter_gray;
$ Display ("binary number = 6 'B % B: Gray en-coded binary number = 6' B % B", counter_binary_reg, counter_gray_reg );
End End

/* Logic is to get Gray code from binary code */
Function[5:0] binary2gray
;
Input[5:0] value;
IntegerI;
Begin 
Binary2gray [5] = value [5];
For(I = 5; I> 0; I
= I-1)
Binary2gray [I-1] = value [I] ^ value [I
-1];
End
Endfunction

/* Get gray encoded output */
Always@(*)
Begin 
Counter_gray = counter_gray_reg;
Counter_binary = counter_binary_reg;
Counter_gray = binary2gray (counter_binary_reg );End
Endmodule 

Iv. Odd-number crossover

Odd division circuit:

The odd-number crossover circuit is commonly used by the dislocation "XOR" method. For example, trigger the trigger counter to trigger the trigger of the rising edge of the clock to be divided by trigger the trigger technique. When the counter counts to the adjacent value, the trigger is flipped twice. For example, when the counter is counted to 1, the output clock is flipped and then flipped when the counter is counted to 2. That is, the counter is flipped twice at the neighboring 1 and 2 moments. The duty cycle is 1/3 or 2/3. if you want to implement a trigger clock with a duty cycle of 50%, trigger the counter and trigger the trigger counter with the rising edge of the clock to be divided, then, phase or budget the triplicate clock generated by the rising and falling edges to get a triplicate clock with a duty cycle of 50%.

Promotion of Misaligned "XOR" method:

For the realization of the duty cycle of 50% n times odd number division, first of all the rise of the model N count triggered, count to a selected value, the output clock flip, and then into (N-1) /2 flip it again to get a technical frequency clock with a non-50% duty cycle. In addition, the module n triggered by the descent edge is counted at the same time, and the selected value of the output clock flip triggered by the rising edge is the same as that of the selected value, and the output clock flip is also performed after (n-1)/2, the output clock is flipped again to generate an odd n-division clock with a non-50% duty cycle. Two phase or operations with a non-50% duty cycle are performed to obtain an odd n-frequency clock with a 50% duty cycle.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.