Summary of the invention
Technical matters to be solved by this invention is: whether a kind of binary number is provided is the verifying attachment and the chip of three multiple, and it can enough less resources, and operation efficiency is judged a binary number faster, and particularly whether bigger number is 3 multiple.
In order to address the above problem, the invention discloses and be used to judge that whether binary number is the verifying attachment of three multiple, described verifying attachment comprises: split cells, first totalizer, second totalizer, first subtracter, first selector, second subtracter, look-up table unit, second selector.
Wherein, split cells is used for described binary number is split into low hyte and high hyte two parts; First totalizer is used to calculate high each bit digital sum of hyte part odd bits of described binary number; Second totalizer is used to calculate high each bit digital sum of hyte part even bit of described binary number; First subtracter, the positive input terminal of this subtracter is connected with the output terminal of described first totalizer, the negative input end of this subtracter is connected with the output terminal of described second totalizer, is used to calculate the difference that each bit digital sum of stating odd bits deducts each bit digital sum of even bit; First selector, the input signal of the first input end of this selector switch is the sign bit of described difference, the input signal of second input end of this selector switch is described difference, and the input signal of the 3rd input end of this selector switch is: described difference is by a phase inverter, the value after left shifter; Second subtracter, the signal of the positive input terminal of this subtracter are the low hyte of described binary number, and the negative input end of this subtracter is connected with the output terminal of described selector switch; The look-up table unit, this look-up table unit is connected with the output terminal of described second subtracter, is used to check that whether described binary number is three multiple; Second selector, the first input end of this selector switch is connected with the output terminal of described look-up table.
Preferably, determine the figure place of described low hyte in the following way:
The value that makes Y is for more than or equal to 4 integer, for inequality:
Bring each Y value successively into, judge whether described inequality is set up, the value of the Y of minimum that described inequality is set up is defined as the figure place of described low hyte.
Preferably, the element in the described look-up table is: 0,3,6,9,12,15.
According to another embodiment of the present invention, a kind of chip is also disclosed, described chip comprises verifying attachment, and described pick-up unit comprises: described verifying attachment comprises: split cells, first totalizer, second totalizer, first subtracter, first selector, second subtracter, look-up table unit, second selector.
Wherein, split cells is used for described binary number is split into low hyte and high hyte two parts; First totalizer is used to calculate high each bit digital sum of hyte part odd bits of described binary number; Second totalizer is used to calculate high each bit digital sum of hyte part even bit of described binary number; First subtracter, the positive input terminal of this subtracter is connected with the output terminal of described first totalizer, the negative input end of this subtracter is connected with the output terminal of described second totalizer, is used to calculate the difference that each bit digital sum of stating odd bits deducts each bit digital sum of even bit; First selector, the input signal of the first input end of this selector switch is the sign bit of described difference, the input signal of second input end of this selector switch is described difference, and the input signal of the 3rd input end of this selector switch is: described difference is by a phase inverter, the value after left shifter; Second subtracter, the signal of the positive input terminal of this subtracter are the low hyte of described binary number, and the negative input end of this subtracter is connected with the output terminal of described selector switch; The look-up table unit, this look-up table unit is connected with the output terminal of described second subtracter, is used to check that whether described binary number is three multiple; Second selector, the first input end of this selector switch is connected with the output terminal of described look-up table.
Compared with prior art, the present invention has the following advantages:
The present invention is by splitting into binary number low hyte and high hyte two parts, calculate the poor of each bit digital sum of odd bits and each bit digital sum of even bit in the high hyte, and just according to difference, the condition of forsaking one's love takes corresponding means to obtain execution result, at last judge that according to execution result and look-up table whether this number is the technological means of 3 multiple, avoided in the prior art, when judging that whether a binary number is three multiple, need this binary number is converted into decimal numeral complex process, and then avoided that each the bit digital addition of this binary number is resulting and excessive and the wide defective of bit wide of subtracter in the deterministic process that causes; Also avoided in the prior art simultaneously, it is more that the binary number iteration subtracts three the iterations that method caused, and can't satisfy the defective that sequential requires.
For instance, judge that whether a binary number 1110_0111_1011_0010 is three multiple, a kind of method is: earlier this binary number is converted to 10 system numbers, this is the transfer process of a relative complex:
(1110_0111_1011_0010)
2=(2
15+ 2
14+ 2
13+ 2
10+ 2
9+ 2
8+ 2
7+ 2
5+ 2
4+ 2
1+ 2
0)
10In this step, calculated amount is bigger, and the decimal number that calculates also is the bigger numeral of a units, and in ensuing judgement, the bit wide of the subtracter of required selection is relatively large; The another kind of method of judging is, directly adopts iteration to subtract three, though avoided complicated numeral system conversion, the bit wide of required subtracter will reach 16, and because number of iterations is more, cause satisfying the requirement of sequential.And use method of the present invention, and judge this binary number, only needing a bit wide is 5 subtracter, and does not need iteration to judge.Comparatively speaking, processing speed obviously accelerates, and chip occupying area is little.
Embodiment
At first, algorithm derivation of the present invention is described:
The characteristics of binary number are that the number of weight of the digital representative on its each and 3 multiple only differ from 1 or 2, and this difference is clocklike, and this rule is if its power is odd number, then differ from 1 with 3 multiple, if its power is even number, then differ from 2 with three multiple.
Illustrate:
(1111_1111)
2=2
7+2
6+2
5+2
4+2
3+2
2+2
1+2
0
2
7=128=129-1,129 can be divided exactly by 3
2
6=64=66-2,66 can be divided exactly by 3
2
5=32=33-1,33 can be divided exactly by 3
2
0=1=3-2,3 can be divided exactly by 3
This shows, a binary digit can be splitted into several multiple sums of 3, from low level, deduct 1 and 2 of filling again.
Core concept of the present invention is: a binary number is splitted into high hyte and low hyte two parts, and wherein, the figure place of low hyte is the subtracter bit wide, and the figure place of the high hyte i.e. total bit of this binary number deducts subtracter bit wide figure place.Further analyze, several sums of the number of each odd bits representative and even bit representative are three multiple.Therefore, before subtracting, can calculate the number what odd bits are arranged earlier, deduct the number number of even bit with this number.If be judged in several high hyte (high position is the figure place that total bit deducts subtracter bit wide figure place rear high-lying) odd bits p 1 is arranged, even bit has q 1, w=p-q.If w just, then can this number be equivalent to by 3 judgements of dividing exactly: judge that can the difference that the low represented number of hyte deducts w be divided exactly by 3; If w is negative, then can this number be equivalent to by 3 judgements of dividing exactly: judge that can the low represented number of hyte deduct w individual 2 and be divided exactly by 3.
For above-mentioned purpose of the present invention, feature and advantage can be become apparent more, the present invention is further detailed explanation below in conjunction with the drawings and specific embodiments.
With reference to Fig. 1, Fig. 1 is that whether binary number is the flow chart of steps of three multiple method of inspection embodiment according to the present invention, comprises the steps:
Step 101: judge that whether described binary number is greater than specifying figure place N(N〉1), if described binary number is split into low hyte and high hyte two parts; For example, N is set to 4, and binary number is split into the low hyte in Y position and the high hyte two parts in N-Y position.For instance, for binary number, 1110_0111_101 ∣ 0_1000 can be split as 5 low hyte parts and 11 high hyte parts.
Step 102: preset a look-up table, described look-up table comprises from 0 to 2
NIn all can be by 3 numbers of dividing exactly; In this example, look-up table should comprise that all can be comprised by 3 numbers of dividing exactly between 0 to 16: 0,3,6,9,12,15.
Step 103: determine odd bits and even bit in the described high hyte part, calculate each bit digital sum of described odd bits, described even bit respectively; According to top example, give this 16 bit everybody compile sequence number: from leftmost side low level: be followed successively by the 0th, the 1st, the 2nd ... the 15th, wherein, high hyte comprises the 5th to the 16th, and each bit digital sum of its odd bits is each bit digital sum 0+1+1+0+1=3 of 1+1+1+0+1+1=5, described even bit.
Step 104: each bit digital sum of judging described odd bits deducts the difference of each bit digital sum of even bit whether greater than 0, if then the number that described low hyte is represented deducts described difference, obtains execution result; If not, the number that described low hyte is represented is as minuend, deducts absolute value with described difference and moves to left after one, obtains the scale-of-two execution result; According to top example, each bit digital sum=5-3=2 of each bit digital sum-even bit of odd bits〉0, belong to the former, what described again low hyte was represented several 01000 is 8: promptly described execution result is 8-2=6.
Step 105: in described look-up table, search described scale-of-two execution result, as find, determine that described binary number is three multiple.Otherwise, be not three multiple.In this example, can in look-up table, find this execution result, so this binary number 1110_0111_1010_1000 is 3 multiple.
Preferably, in described splitting step, determine the figure place of described low hyte in the following way,, comprise the steps: with reference to Fig. 2
Step 201: the total bit that makes binary number is N, the figure place Y of the low hyte of order, and the figure place in the then high hyte is N-Y, the initial value that makes Y is 4;
Step 202: judge inequality
Whether set up, if set up, then execution in step 204; If be false execution in step 203;
Step 203: the value that makes Y is from adding 1, X=N-Y; And, return execution in step 202;
Step 204: the value of determining Y.
Should hang down the figure place of hyte and determine that method mainly was based on following principle:
If be judged number for the N position, the figure place of low hyte is the Y position, X for need split into 3 multiple and the figure place of power, then establish X=N-Y, the fractionation of number as shown in Figure 3.
When X was even number, then several sums of the weight of per two representatives just will be replenished one 3 in the high position.Extreme case is that all there is number the X position in the high position, and the minuend that need this moment is at least
When X was odd number, then several sums of the weight of per two representatives just will be replenished one 3 in the high position, and remaining needs replenish 2 or 1.Extreme case is that all there is number the X position in the high position, and when the additional number of needs was 2, the minuend that need this moment was at least:
When the additional number of needs was 1, the minuend that need this moment was at least.
Comprehensive above-mentioned two kinds of situations, the number that needs to replenish under extreme case is:
And the number of the maximum that the Y bit can provide is 2
Y
As the above analysis, if N 〉=4 then need to satisfy:
Preferably, the numerical value in the described look-up table is decided to be: 0,3,6,9,12,15.If because if the multiple of a binary number 3, the described execution result that obtains according to the method described above all should all should be three multiple, for avoiding the numerical value in the look-up table too much, number of times relatively is too much, so a preferred implementation of this method can be selected: 0,3,6,9,12,15.Should be noted that: this method is not done any qualification at this, can adopt more numerical value in the look-up table yet, such as: 0,3,6,9,12,15,18,21, perhaps more can be by 3 numbers of dividing exactly.
Describe the present invention in detail below in conjunction with an instantiation and how to realize that mostly is the checkout procedure whether binary number is three multiple:
If whether judge binary number 1101_0110_1110 is three multiple, specifically deterministic process is as follows: at first preset a look-up table, described look-up table comprises 0,3,6,9,12,15; Judge as follows then:
Step 401: judge to be judged binary number 1101_0110_1110 greater than 4? if not, execution in step 402 then; If, execution in step 403.
Because this binary number is 16, so direct execution in step 403:
Step 403: calculate each bit digital sum of odd bits and high hyte in the high hyte part partly in each bit digital sum of even bit poor.
According to this estimative number, at first described binary number is split into the low hyte in Y position and the high hyte two parts in N-Y position.Wherein, from Y=4, the checking inequality
Whether set up.Count hereto, with X=8, Y=4 substitution inequality, inequality is set up, therefore, and Y=4, X=8 does not need to continue to attempt new Y value.And each the bit digital sum of odd bits in the high hyte part is 2, and each bit digital sum of even bit is 3, and the difference that each bit digital sum of odd bits deducts each bit digital sum of even bit is W=2-3=-1.
Step 404: judge that above-mentioned difference W is greater than 0? if, execution in step 405, if not, execution in step 406.
Because the difference W=-1 that obtains in the step 403, so less than 0, execution in step 406
Step 406: move to left one result's difference D of the absolute value that calculates binary number that low hyte represents and W.
Because the number (1110) that low hyte is represented
2Be 14, the result that the absolute value that the number that described low hyte is represented deducts described difference moves to left and obtains after, the execution result 14-1 that obtains * 2=12=(1100)
2
Step 407: D as the new number that is judged, is returned execution in step 401, judge to be judged binary number (1100)
2Greater than 4?
Because (1100)
2Be 4, execution in step 402 judges whether this number is 0,3,6,9, and among 12,15 one is because (1100)
2Expression 12 can be found this binary number (1101_0110_1110) in the described look-up table
2It is 3 multiple.
Here need to prove: if the number that described low hyte is represented deducts the result that the absolute value of described difference moves to left and obtains after, the execution result that obtains is greater than 4, that is to say that maximal value 15 in look-up table is less than this execution result, then need to carry out iteration, concrete grammar is, execution result is judged as the new number that is judged, up to subtracter in 4.For one 26 binary number, it is 5 that low hyte should be delimited, and in concrete deterministic process, then needs to carry out twice iteration and judges.
With reference to Fig. 5, Fig. 5 is the structural representation of the embodiment of verifying attachment according to the present invention, comprises following structure:
Split cells 508 is used for described binary number is split into low hyte and high hyte two parts;
First totalizer 501 is used to calculate high each bit digital sum of hyte part odd bits of described binary number;
Second totalizer 502 is used to calculate high each bit digital sum of hyte part even bit of described binary number;
First subtracter 503, the positive input terminal of this subtracter is connected with the output terminal of described first totalizer, the negative input end of this subtracter is connected with the output terminal of described second totalizer, is used to calculate the difference that each bit digital sum of stating odd bits deducts each bit digital sum of even bit;
First selector 504, the input signal of the first input end of this selector switch is the sign bit of described difference, the input signal of second input end of this selector switch is described difference, the input signal of the 3rd input end of this selector switch is: described difference is by a phase inverter, the value after left shifter;
Second subtracter 505, the signal of the positive input terminal of this subtracter are the low hyte of described binary number, and the negative input end of this subtracter is connected with the output terminal of described selector switch;
Look-up table unit 506, this look-up table unit is connected with the output terminal of described second subtracter, is used to check that whether described binary number is three multiple;
Second selector 507, the first input end of this selector switch is connected with the output terminal of described look-up table.
With reference to Fig. 6, Fig. 6 is the structural representation of the embodiment of verifying attachment according to the present invention, and it partly is 4 binary number that this device can be used to check low hyte.
According to a further aspect in the invention, the present invention also provides a kind of chip, and this chip comprises the verifying attachment of being told.The structure of this verifying attachment is identical with top description, does not repeat them here.
To sum up, in the present invention:
By binary number being split into low hyte and high hyte two parts, calculate the poor of each bit digital sum of odd bits and each bit digital sum of even bit in the high hyte, and just according to difference, the condition of forsaking one's love takes corresponding means to obtain execution result, at last judge that according to execution result and look-up table whether this number is the technological means of 3 multiple, overcome in the prior art, the numerical value conversion is complicated, the long chip area that is caused of required subtracter bit wide is relatively large, defectives such as inefficiency, thereby, the enough minimum resources of energy, the fastest operation efficiency, judge a number, particularly whether bigger number is 3 multiple.
Each embodiment in this instructions all adopts the mode of going forward one by one to describe, and what each embodiment stressed all is and the difference of other embodiment that identical similar part is mutually referring to getting final product between each embodiment.For system embodiment, because it is similar substantially to method embodiment, so description is fairly simple, relevant part gets final product referring to the part explanation of method embodiment.
More than whether be that three the multiple method of inspection, verifying attachment, chip are introduced to a kind of binary number provided by the present invention, used specific case herein principle of the present invention and embodiment are set forth, the explanation of above embodiment just is used for helping to understand method of the present invention and core concept thereof; Simultaneously, for one of ordinary skill in the art, according to thought of the present invention, the part that all can change in specific embodiments and applications, in sum, this description should not be construed as limitation of the present invention.