BCD code processing method based on decimal multiplication and computer equipment

Through the BCD code processing method based on decimal multiplication, the multiplication operation of decimal numbers is directly performed, which solves the problems of cumbersome and low speed of computer multiplication operations, and simplifies the operation process and improves efficiency.

CN118885152APending Publication Date: 2024-11-01GUANGDONG ANZHENG COMPUTER FORENSIC EXPERTISE INST +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410931235.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-03-21
Publication Date
2024-11-01

AI Technical Summary

Technical Problem

When a computer performs decimal number multiplication operation, it needs to convert the numerical value into binary for calculation, resulting in cumbersome and low speed.

Method used

The BCD code processing method based on decimal multiplication is adopted. By obtaining the decimal number of the multiplier and multiplier, the corresponding BCD code is determined, and the multiplication operation is performed to directly output the final product, avoiding the binary conversion process.

Benefits of technology

It simplifies the computing process inside the computer, improves the computing speed and efficiency, and reduces physical circuits and power consumption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118885152A_ABST
    Figure CN118885152A_ABST
Patent Text Reader

Abstract

The invention discloses a BCD code processing method based on decimal multiplication and computer equipment, and relates to the field of computer operation, and the method comprises the steps: obtaining a multiplicand and a multiplier which are decimal numbers; the method comprises the following steps: determining a BCD code corresponding to a multiplicand, the BCD code comprising a 8421 BCD code and a 5421 BCD code, determining a 5221 BCD code corresponding to a multiplier, and determining that the BCD code used by the multiplicand is the 8421 BCD code or the 5421 BCD code when the multiplicand is multiplied with each digit according to the digit of the 5221 BCD code of the multiplier; and obtaining a partial product corresponding to the digits of the multiplicand and the multiplier, performing shift addition on the partial product, and determining a final product corresponding to the multiplicand and the multiplier, the final product being the 8421BCD code. According to the invention, when the multiplication operation is carried out on the two decimal numbers through the computer, the system conversion is not needed, and the processing speed of the computer is improved.
Need to check novelty before this filing date? Find Prior Art

Description

[0001] This application is a divisional application of a patent application entitled "BCD code processing method, device, equipment and medium based on decimal multiplication". The application date of the original application is March 21, 2023, and the application number is 202310277845.4. Technical Field

[0002] The present invention relates to the field of computer operation technology, and in particular to a BCD code processing method based on decimal multiplication and a computer device. Background Art

[0003] From its birth to today, computers have undergone many iterations of development and have made significant contributions to solving scientific computing problems with their ever-increasing computing speeds, even hundreds of millions of times per second or more.

[0004] At present, the common method for converting decimal numbers into binary numbers is to divide the decimal number by the number two continuously and reverse the remainder. To convert a binary number into a decimal number, it is necessary to add up the weights of each digit of the binary number into a decimal number. Computers are based on the switching characteristics of circuits and are implemented with two digital numbers 0 and 1. Therefore, since the birth of computers, arithmetic operations have all been performed using binary operations. If humans input the multiplication of two decimal numbers into a computer, the computer needs to convert both decimal numbers into binary numbers for the multiplication of decimal numbers, and then convert the binary multiplication results into decimal numbers. This generates a large number of operations that do not require actual results, and a huge amount of operations have been performed before the arithmetic operations are performed, which is a waste of operations. Therefore, the operation process of computers for multiplying decimal numbers is relatively cumbersome and the operation speed is low. Summary of the invention

[0005] The embodiment of the present invention provides a BCD code processing method based on decimal multiplication and a computer device to solve the problem that the operation process is relatively complicated and the operation speed is low when the computer performs multiplication operation on decimal numbers.

[0006] To achieve the above objectives, this application provides the following solutions:

[0007] In a first aspect, the present application provides a BCD code processing method based on decimal multiplication, comprising:

[0008] Get the multiplicand and the multiplier; both the multiplicand and the multiplier are decimal numbers;

[0009] Determine the BCD code corresponding to the multiplicand and the 5221BCD code corresponding to the multiplier; the BCD code corresponding to the multiplicand includes the 8421BCD code and the 5421BCD code;

[0010] According to the number of digits of the 5221BCD code of the multiplier, determine whether the BCD code used by the multiplicand is 8421BCD code or 5421BCD code when the multiplicand is multiplied by each digit;

[0011] Obtain the partial products corresponding to the number of bits of the multiplicand and the multiplier, and add the partial products to determine the final product corresponding to the multiplicand and the multiplier; the final product is 8421BCD code, wherein, if there is a carry from one group to the next group during the addition, then add the 8421BCD code number 0110 to the group.

[0012] In a first aspect, the present application provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned BCD code processing method based on decimal multiplication when executing the computer program.

[0013] According to the specific embodiments provided in this application, this application discloses the following technical effects:

[0014] The present application provides a BCD code processing method and a computer device based on decimal multiplication. Decimal numbers are multiplied by BCD code processing. There is no need to convert the multiplier and the multiplicand into binary numbers inside the computer. The operation process is relatively simplified and the operation speed is greatly improved. Since there is no base conversion process, the internal operation process of the computer is simplified, the physical circuit and power consumption of the computer are reduced, and the operation efficiency of the computer is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0016] Figure 1 A schematic diagram of an application environment of a BCD code processing method based on decimal multiplication in one embodiment of the present invention;

[0017] Figure 2 A first flow chart of a BCD code processing method based on decimal multiplication in one embodiment of the present invention;

[0018] Figure 3 A second flow chart of a BCD code processing method based on decimal multiplication in one embodiment of the present invention;

[0019] Figure 4 Schematic diagram of the manual calculation steps of the BCD code processing method based on decimal multiplication in one embodiment of the present invention;

[0020] Figure 5 Another schematic diagram of a manual calculation step of a BCD code processing method based on decimal multiplication in one embodiment of the present invention;

[0021] Figure 6 Another schematic diagram of a multiplication calculation step of a BCD code processing method based on decimal multiplication in one embodiment of the present invention;

[0022] Figure 7 Schematic diagram of a BCD code processing device based on decimal multiplication in one embodiment of the present invention;

[0023] Figure 8 FIG. 1 is a schematic diagram of a computer device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0024] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0025] The BCD code processing method based on decimal multiplication provided by the embodiment of the present invention can be applied to Figure 1 In the application environment, the BCD code processing method based on decimal multiplication is applied in a BCD code operation system based on decimal multiplication, and the BCD code operation system based on decimal multiplication includes a client and a server, wherein the client communicates with the server through a network. The client, also known as the user end, refers to a program corresponding to the server that provides local services to the client. Furthermore, the client is a computer-side program, an APP program for a smart device, or a third-party applet embedded in other APPs. The client can be installed on, but not limited to, various personal computers, laptops, smart phones, tablet computers, portable wearable devices and other devices. The server can be implemented with an independent server or a server cluster consisting of multiple servers. Specifically, the server is a computer.

[0026] In an exemplary embodiment, the BCD code processing method based on decimal multiplication provided in the present application is run in a computer, and the product operation of two decimal numbers is realized through the cooperation of components such as multipliers, registers, and memories inside the computer. During the operation, there is no need to convert the decimal number into a binary number, nor is there a need to convert the binary number into a decimal number, thereby improving the processing speed of each component inside the computer.

[0027] In an exemplary embodiment, the BCD code processing method based on decimal multiplication provided by the present application is applied in scenarios such as automobile fuel consumption calculation and electricity fee calculation. Specifically, when applied in the scenario of automobile fuel consumption calculation, a multiplier and a multiplicand are obtained by a computer, wherein the multiplier is the amount of gasoline consumed per kilometer of travel of the automobile, and the multiplicand is the total kilometers traveled. The automobile fuel consumption is calculated by the BCD code processing method based on decimal multiplication provided by the present application. Since the calculation process does not involve base conversion, the calculation efficiency of automobile fuel consumption is improved.

[0028] In one embodiment, if Figure 2 As shown, a BCD code processing method based on decimal multiplication is provided, and the method is applied in Figure 1 The server in the example is used as an example, and the specific steps include the following:

[0029] S10. Obtain a multiplicand and a multiplier, where the multiplicand and the multiplier are decimal numbers.

[0030] Among them, multiplication refers to a shortcut method of adding the same numbers. The result of the operation is called a product, and "×" or "*" is the multiplication sign. The numbers before and after the multiplication sign are called factors. The number before the multiplication sign is the multiplicand, and the number after the multiplication sign is the multiplier.

[0031] Specifically, when decimal multiplication is input to the computer, the server obtains the multiplicand and the multiplier.

[0032] S20. Determine the BCD code corresponding to the multiplicand, the BCD code includes 8421BCD code and 5421BCD code, and determine the 5221BCD code corresponding to the multiplier.

[0033] Among them, BCD code (Binary-Coded Decimal) uses 4 binary digits to represent the 10 digits 0 to 9 in a 1-digit decimal number. It is a binary digital encoding form, a decimal code encoded in binary. BCD code is essentially a decimal number. BCD code includes 8421BCD code, 5421BCD code and 5221BCD code.

[0034] The corresponding relationship between the 10 numbers 0 to 9 in decimal numbers and binary numbers and BCD codes is shown in Table 1 below:

[0035] Table 1

[0036] Decimal Numbers Binary Numbers 8421BCD code 5421BCD code 5221BCD code 0 0 0000 0000 0000 1 1 0001 0010 0001 2 10 0010 0010 0010 3 11 0011 0011 0011 4 100 0100 0100 0110 5 101 0101 1000 1000 6 110 0110 1001 1001 7 111 0111 1010 1010 8 1000 1000 1011 1011 9 1001 1001 1100 1110

[0037] The relationship between the decimal number 10-15 and the 8421 code is shown in Table 2 below:

[0038] Table 2

[0039] Decimal Numbers 8421BCD code 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111

[0040] Specifically, after the server obtains the decimal multiplicand and multiplier, it can determine the 8421BCD code and 5421BCD code corresponding to the multiplicand, and the 5221BCD code corresponding to the multiplier according to the corresponding relationship in Table 1. For example: the decimal multiplicand is 2345, then the 8421BCD code corresponding to 2345 is 0010001101000101; the 5421BCD code corresponding to 2345 is 0010001101001000; the decimal multiplier is 62, then the 5221BCD code corresponding to 62 is 10010010.

[0041] S30. According to the number of digits of the 5221BCD code of the multiplier, determine whether the BCD code used by the multiplicand when performing multiplication operation with each digit is 8421BCD code or 5421BCD code.

[0042] The digit number may be the Xth digit of the Xth group. For example, the 5221BCD code corresponding to the multiplier 62 is 10010010. The 5221BCD code has two groups, which are the first digit, the second digit, the third digit, and the fourth digit from right to left (from low to high). Then the first digit of the second group, the fourth digit of the second group, and the second digit of the first group of the 5221BCD code are all 1.

[0043] Specifically, after the method obtains the 5221BCD code of the multiplication, it is necessary to perform a multiplication operation on the multiplicand and the multiplier. The method is to multiply each digit of the multiplier with the multiplicand respectively. However, in the multiplication process, due to the different digits of the multiplier, the BCD code used in the multiplicand operation may also be different. For example: if the digit of the 5221BCD code of the multiplier is the first digit, then it is determined that when the multiplicand is multiplied with the number corresponding to the first digit, the BCD code used by the multiplicand is 8421BCD code; if the digit of the 5221BCD code of the multiplier is the second digit, then it is determined that when the multiplicand is multiplied with the number corresponding to the second digit, the BCD code used by the multiplicand is 5421BCD code.

[0044] S40. Obtain the partial products corresponding to the number of bits of the multiplicand and the multiplier, and add the partial products to determine the final product corresponding to the multiplicand and the multiplier. The final product is 8421BCD code. If there is a carry from one group to the next group during the addition, then the number 0110 of the 8421BCD code is added to the group.

[0045] The server obtains the partial product corresponding to the number of digits of the multiplicand and the multiplier, and performs shift addition (the lowest bit of the partial product at the 3rd bit needs to be aligned with the lowest bit of the partial product at the 2nd bit, and the rest are added one bit apart), and determines the final product corresponding to the multiplicand and the multiplier. The final product is 8421BCD code, wherein, if there is a carry to the upper group during addition, the number 0110 of the 8421BCD code is added to the group. The decimal number corresponding to the final product is output. The computer can directly obtain all partial products, and perform shift addition on the partial products to obtain the final product.

[0046] like Figure 4 , Figure 5 and Figure 6 As shown, in Figure 4 The third last digit "1" in the product 000100111110110100110000 is generated when the second last group carries to the third last group. Therefore, it is necessary to add the 8421BCD code number 0110 to the second last group to make the final product 000100111110110110010000. The reasons are as follows:

[0047] The number composed of 8421BCD code is called 8421 code number for short. When two 8421 code numbers are added, they are added according to binary addition, but when each group of 8421 code numbers carries to the previous group of 8421 code numbers, the current group of 8421 numbers must add 6 (add 0110 in binary and 0110 in 8421BCD code).

[0048] For example: 8+9=17

[0049]

[0050] The result is that the coded number 8421 is incorrect. According to the calculation rules, if there is a carry in the highest digit of each group, 0110 should be added:

[0051]

[0052] 10111, from low to high, four bits in a group, the highest bit has only one 1, not enough for four bits, three 0s are added in front, becoming 00010111, according to the meaning of the 8421 code, which is 17 in decimal, and the result is correct. In other words, when adding, the trigger switch should be set in the lowest bit of each group. The addition operation of BCD coded numbers is often optimized using the remainder 3 code.

[0053] In this application, when the computer obtains two decimal numbers, it multiplies them according to the corresponding BCD code numbers, and the final product obtained is 8421BCD code, which can be subsequently output as a decimal number. In this way, there is no need to use a complicated processing method (i.e., converting a decimal number into a binary number, a common method is to divide the decimal number by 2 continuously, and reverse the remainder. To convert a binary number into a decimal number, it is necessary to add up the weights of each digit of the binary number into a decimal number). It is only necessary to directly arrange each decimal number in the original order through the corresponding relationship in Table 1.

[0054] The algorithm is simple to operate. When performing decimal multiplication, there is no need to convert the multiplier and multiplicand into binary numbers before multiplying them. The operation process is relatively simple and the operation speed is greatly improved. Since there is no base conversion, the internal operation module of the computer is simplified, reducing the physical circuit and power consumption, while increasing stability.

[0055] In one embodiment, if Figure 3 As shown, in step S30, that is, according to the number of digits of the 5221BCD code of the multiplier, it is determined whether the BCD code used by the multiplicand is 8421BCD code or 5421BCD code when the multiplicand is multiplied by each digit, which specifically includes the following steps:

[0056] S301. Divide the multiplicand into groups of four from the lowest digit to the highest digit.

[0057] S302. If the number of digits of the 5221BCD code of the multiplier is the first digit, it is determined that when the multiplicand is multiplied by the digit corresponding to the first digit, the BCD code used by the multiplicand is the 8421BCD code.

[0058] S303. If the number of digits of the 5221BCD code of the multiplier is the second digit, it is determined that when the multiplicand is multiplied by the number corresponding to the second digit, the BCD code used by the multiplicand is the 5421BCD code.

[0059] S304. If the number of digits of the 5221BCD code of the multiplier is the third digit, it is determined that when the multiplicand is multiplied by the number corresponding to the third digit, the BCD code used by the multiplicand is the 5421BCD code.

[0060] S305. If the number of digits of the 5221BCD code of the multiplier is the fourth digit, it is determined that when the multiplicand is multiplied by the number corresponding to the fourth digit, the BCD code used by the multiplicand is the 8421BCD code.

[0061] Among them, the method divides the multiplier into groups of four from low to high; the number of digits in the group can be the Xth digit of the Xth group. For example, the 5221BCD code corresponding to the multiplier 62 is 10010010. The 5221BCD code has two groups, which are the first digit, the second digit, the third digit and the fourth digit from right to left (from low to high). Then the first digit of the second group, the fourth digit of the second group and the second digit of the first group of the 5221BCD code are all 1.

[0062] Specifically, the method selects a code system (8421BCD code or 5421BCD code) corresponding to the multiplicand according to the 5221BCD code of the multiplier; if the number of digits of the 5221BCD code of the multiplier is the first digit of each group, it is determined that when the multiplicand is multiplied by the number corresponding to the first digit, the BCD code used by the multiplicand is the 8421BCD code; if the number of digits of the 5221BCD code of the multiplier is the second digit, it is determined that when the multiplicand is multiplied by the number corresponding to the second digit, the BCD code used by the multiplicand is the 5421BCD code; if the number of digits of the 5221BCD code of the multiplier is the third digit, it is determined that when the multiplicand is multiplied by the number corresponding to the third digit, the BCD code used by the multiplicand is the 5421BCD code; if the number of digits of the 5221BCD code of the multiplier is the fourth digit, it is determined that when the multiplicand is multiplied by the number corresponding to the fourth digit, the BCD code used by the multiplicand is the 8421BCD code.

[0063] For example: Figure 4 As shown, take 2345*62 as an example. The 5221 code of 62 is: 10010010; the 8421 BCD code of 2345 is: 0010001101000101, and the 5421 BCD code is 0010001101001000. Figure 4As shown. The first bit of 10010010 is 0, and each bit of 2345 takes the 8421 BCD code (0010001101000101), and multiplies it by the number 0 in the first bit, and the partial product of the first bit is 000000000000000; the second bit of 10010010 is 1, and each bit of 2345 takes the 5421 BCD code (0010001101001000), and multiplies it by the number 1 in the second bit, and the partial product of the second bit is 0010001101001000; the third bit of 10010010 is 0, and each bit of 2345 takes the 5421 BCD code (0010001101001000), And multiply it by the number 0 in the third digit, and the partial product of the third digit is 0000000000000000; the 4th digit of 10010010 is 0, and each digit of 2345 takes the 8421BCD code (0010001101000101), and multiply it by the number 0 in the fourth digit, and the partial product of the fourth digit is 000000000000000; the 4th digit of the second group of 10010010 is 1, and each digit of 2345 takes the 8421BCD code (0010001101000101), and multiply it by the number 1 in the fourth digit of the second group, and the initial partial product of the 4th digit of the second group is 0010001101000101.

[0064] Moreover, the initial partial product of the 4th bit of the 2nd group 0010001101000101 is a 5421BCD code, which needs to be converted into an 8421BCD code before it can be added to other partial products (when the fourth digit is 1, it is equivalent to multiplying the multiplicand by the number 5. According to steps S3051 and S3052, it can be known that the 1 of the fourth digit of each group in 0010001101000101*1000=0010001101000101000 must be changed to 0, and 0101 must be added to the changed group, that is, it becomes 0010001011100100101). At this time, 0010001011100100101 is the 8421BCD code corresponding to the initial partial product 0010001101000101. When the partial products are added, 0010001011100100101 replaces the position of 0010001101000101.

[0065] Shift and add the partial products (the lowest bit of the third-bit partial product needs to be aligned with the lowest bit of the second-bit partial product), and we get Figure 4The product is 000100111110110100110000. However, the third-to-last digit "1" in 000100111110110100110000 is generated when the second-to-last group carries to the third-to-last group. Therefore, it is necessary to add the 8421BCD number 0110 to the second-to-last group to make the final product 000100111110110110010000 in 8421BCD. At the same time, 000100111110110110010000 can also be expressed as 13141390 in 8421BCD (13 in 1 and 4 in 14 are added to form 5, and 14 in 1 and 3 are added to form 4). The decimal number corresponding to 13141390 is 145390, and the result is correct.

[0066] In addition, if Figure 6 As shown, when the decimal multiplicand is obtained, the 5421BCD code of the multiplicand can also be directly converted into the 8421BCD code. During the operation of the computer, the 5421BCD code can also be run first to convert the 5421BCD code into the 8421BCD code required for the subsequent steps.

[0067] That is, this method determines the 5421BCD code of the multiplicand, then right-shifts the multiplicand corresponding to the 5421BCD code by three bits, converts the highest bit value 1 of each group into a value 0, and then adds the value 0101 of the 8421BCD code to the corresponding converted group to generate the target multiplicand, which is the 8421BCD code of the multiplicand.

[0068] Or, if it is determined that the value of the fourth bit of the 5221BCD code of the multiplier is 1, the multiplicand corresponding to the 5421BCD code is shifted right by three bits, the value 1 of the highest bit of each group is converted into a value 0, and then the value 0101 of the 8421BCD code is added to the corresponding converted group to generate the target multiplicand, which is the 8421BCD code of the multiplicand.

[0069] The purpose of steps S301 to S305 is that, in order to obtain a correct final product, the BCD code system of the multiplicand needs to be selected according to the 5221 BCD code of the multiplier.

[0070] In one embodiment, if Figure 3 As shown, in step S40, the partial products corresponding to the number of bits of the multiplicand and the multiplier are obtained, and the partial products are added to determine the final product corresponding to the multiplicand and the multiplier, which specifically includes the following steps:

[0071] S401. Clear the original partial product.

[0072] S402. Determine whether the multiplicand should be added to the original partial product based on the last digit value of the multiplier, and shift the original partial product right by one digit to form a new partial product.

[0073] S403. Shift the multiplier right by one position, use the original second lowest position as the new last position value, and leave the highest position of the multiplier vacated and place the lowest position of the original partial product.

[0074] S404. Repeat the step of determining whether the multiplicand is to be added to the original partial product based on the last digit of the multiplier until after the highest digit of the multiplier.

[0075] S405. Use the partial product as the high-order value of the final product, and use the multiplier as the low-order value of the final value.

[0076] Among them, Figure 4 The figure shows the manual calculation steps for the multiplier and multiplicand. All partial products are listed and added at the same time. However, in the computer calculation process, in order to reduce storage space, the partial products can be gradually shifted and added.

[0077] Specifically, the method obtains the original partial product and clears the original partial product to zero. For example, the 5221 code of the multiplier 62 is 10010010, and the last digit of the multiplier is 0, which is not added to the original partial product 0. The original partial product is shifted right by one digit to form a new partial product of 0.

[0078] Shift the multiplier 10010010 right by one position, and the multiplier becomes 01001001. The value 1 corresponding to the original second lowest position is used as the new last position value 1, and the highest position of the multiplier is left empty to put the lowest position value 0 of the partial product.

[0079] The new last digit value 1 determines the addition of the multiplicand and the original partial product, and the added value is (010001101001000, the 5124BCD code of the multiplicand). 010001101001000 is shifted right by one bit to 01000110100100, and 001000110100100 is used as the new partial product (the new partial product is used as the original partial product of the next cycle);

[0080] Shift the multiplier 01001001 right by one position, and the multiplier becomes 00100100. The value 0 corresponding to the original second lowest position is used as the new last position value 0, and the highest position of the multiplier is vacated to place the lowest position value 0 of the partial product; each code number is one position higher, and in principle, the position of the product is also one position higher, but the third position of D has the same weight as the second position, because the weights are both 2, so the third position and the second position of the partial product are in the same position.

[0081] The new last digit value 1 is 0, which is not added to the original partial product 010001101001000. The original partial product is 001000110100100. The original partial product is not shifted right by one place, forming a new partial product of 01000110100100.

[0082] Shift the multiplier 00100100 right by one position, the multiplier becomes 00010010, and the value 0 corresponding to the original second lowest bit is used as the new last bit value 0, and the highest bit of the multiplier is left empty to place the lowest bit value 0 of the partial product; then repeat the step of determining whether the multiplicand is added to the original partial product based on the last bit value of the multiplier until after the highest bit 1 based on the multiplier (when the last bit value is the highest bit, a loop is required, otherwise it is not required), and use the partial product as the high bit value of the final product, and the multiplier as the low bit value of the final value.

[0083] At this time, the multiplier is 10010000, the partial product is 0001001111101101, and the final product is 000100111110110110010000 in 8421BCD code; the decimal value corresponding to the final product is 145390. In addition, it can be seen that 2345*62=145390 is correct, so this method is correct.

[0084] Similarly, Figure 5 and Figure 6 The multiplication formula shown can also be processed in this way.

[0085] The purpose of step S401 to step S405 is to perform a cumulative loop on the partial products, thereby further reducing the computing time and storage space of the computer and improving computing efficiency.

[0086] In one embodiment, if Figure 3 As shown, in step S40, the partial products corresponding to the number of bits of the multiplicand and the multiplier are obtained, and the partial products are added to determine the final product corresponding to the multiplicand and the multiplier, which specifically includes the following steps:

[0087] S406. When it is determined that the last digit of the multiplier is the third digit of the initial multiplier, the original partial product is not shifted right by one digit.

[0088] S407. Shift the multiplier right by one position, and use the second lowest position as the new last position value. Leave the highest position of the multiplier empty and do not place the lowest position of the partial product.

[0089] The third digit of the initial multiplier is the third digit (3rd digit) of each group. Figure 4 In the blue part shown, the partial products of the 3rd digit of group 1 and the 3rd digit of group 2 are aligned with the position of the 2nd digit and do not need to be shifted.

[0090] Specifically, the reason for this embodiment is that each code number is one digit higher, and in principle, the position of the product is also one digit higher. Since the weight of the third digit code of D is the same as that of the second digit, which is also 2, the position of the third digit partial product is the same as that of the second digit partial product. In the computer operation process, when the last digit value of the multiplier is determined to be the third digit of the initial multiplier, the original partial product is not shifted right by one digit; the multiplier is shifted right by one digit, and the second lowest digit is used as the new last digit value, and the highest digit of the multiplier is vacated without placing the lowest digit of the partial product; the rest is performed in the same manner as steps S402 to S405.

[0091] In one embodiment, if Figure 3 As shown, after step S305, that is, if the number of digits of the 5221BCD code of the multiplier is the fourth digit, it is determined that when the multiplicand is multiplied by the number corresponding to the fourth digit, the BCD code used by the multiplicand is the 8421BCD code, the following steps are specifically included:

[0092] S3051. Determine that the value of the fourth bit of the 5221BCD code of the multiplier is 1.

[0093] S3052. Shift the multiplicand right by three bits, convert the highest bit value 1 of each group into the value 0, and then add the value 0101 of the 8421BCD code to the corresponding converted group to generate the target multiplicand, which is used to add the target multiplicand to the original partial product.

[0094] Among them, because C*5 (multiplicand C*multiplier 5), the product is 5421BCD code. 5421BCD code must be converted to 8421BCD code before it can be added to the 8421BCD code of other digits. The 8421BCD code of 5 is 0101. The conversion method is to take the 8421BCD code of C and add three 0s, and then group the 4 digits from low to high, change the highest 1 in each group to 0, and add 0101 to the group. See Figure 4 The red part is shown. Since the fourth digit is 1, it is equal to multiplying by 5. We need to change the fourth digit 1 of each group in 0010001101000101*1000=0010001101000101000 to 0101 and add it to the current group, that is, it becomes 0010001011100100101, and then add it to the number of rows.

[0095] Specifically, when the conversion method is run in a computer, the computer determines that the value of the fourth bit of the 5221BCD code of the multiplier is 1, shifts the multiplicand right by three bits (equivalent to adding three 0s to the 8421BCD code), converts the value 1 of the highest bit (the fourth bit) of each group into a value 0, and then adds the value 0101 of the 8421BCD code to the corresponding converted group to generate a target multiplicand, which is used to add the target multiplicand to the original partial product.

[0096] In one embodiment, if Figure 3As shown, a BCD code processing method based on decimal multiplication is provided, which specifically includes the following steps:

[0097] S51. When the multiplier value is 5, determine the 8421BCD code of the multiplicand.

[0098] S52. Shift the multiplicand of the 8421BCD code right by three bits, and use the multiplicand after the right shift as the first result product of the multiplicand and the multiplier, the coding system of the first result product is the 5421BCD code.

[0099] Among them, the decimal multiplicand C is multiplied by the multiplier D, and the product is E, that is, C*D=E;

[0100] Specifically, when the multiplier value is 5 (D=5), the multiplicand takes the 8421 BCD code, 5 takes the 5421 code, that is, when 5 takes 1000, the result of C*1000 is shown in Table 3:

[0101] Table 3

[0102]

[0103] It can be seen that when the multiplicand C takes the 8421 code, 5 takes the 5421 code, which is 1000, three zeros are added to the right side of the 8421 BCD code (that is, *1000), and the product E takes the 5421 code, the product can be directly obtained.

[0104] Then add three zeros to the right side of the 8421BCD code. The computer needs to shift the multiplicand of the 8421BCD code right by three bits, and use the multiplicand after right shift as the first result product of the multiplicand and the multiplier. The coding system of the first result product is 5421BCD code.

[0105] In addition, the multiplier value may also be the number of digits of the multiplier. For example, when the multiplier is 2345, and the multiplication operation is performed on the number of digits of the multiplier 5, this embodiment is also applicable.

[0106] In one embodiment, if Figure 3 As shown, a BCD code processing method based on decimal multiplication is provided, which specifically includes the following steps:

[0107] S53. When the multiplier value is 2, determine the 5421BCD code of the multiplicand.

[0108] S54. Shift the multiplicand of the 5421BCD code right by one position, and use the multiplicand after the right shift as the second result product of the multiplicand and the multiplier, the coding system of the second result product is the 8421BCD code.

[0109] Among them, the decimal multiplicand C is multiplied by the multiplier D, and the product is E, that is, C*D=E;

[0110] Specifically, when the multiplier value is 2 (D=2), in the 8421BCD code system, the 5421BCD code system, and the 5221BCD code system, 2 can be expressed as 0010, so C*2 can be expressed as C*0010. If C is binary, directly adding a 0 to the right side of C is the result of multiplying the binary number by 2. However, if other appropriate encodings are used, C*0010, a 0 can also be directly added to the right side of C, as shown in Table 4.

[0111] Table 4

[0112]

[0113]

[0114] Table 4 shows that the decimal number C is coded as 5421, the code of 2 is 0010, and adding a 0 to the right of the 5421 BCD code of C (i.e. *0010) gives the product E of C*2. E is also coded as 8421 BCD.

[0115] Then add a 0 on the right side of the 5421BCD code of C. The computer needs to shift the multiplicand of the 5421BCD code right by one position, and use the multiplicand after right shift as the second result product of the multiplicand and the multiplier. The coding system of the second result product is 8421BCD code.

[0116] In addition, the multiplier value may also be the number of digits of the multiplier. For example, when the multiplier is 2345, when the multiplication operation is performed on the number of digits of the multiplier 2, this embodiment is also applicable.

[0117] in addition:

[0118] (1) D = 0. C can be represented as 0000 using 8421BCD or any other encoding. No matter what number C is, C*0 = 0, that is, each digit of C is 0000, which is the product.

[0119] (2) D = 1. C can be represented as 0001 using 8421 or any other encoding. Since C*1 = C, 1 can be represented by different encoding systems as needed. C*1 is equal to the 8421 encoding of C.

[0120] In summary, the product of any decimal number C and 0, 1, 2, 5 (decimal number D) is E, that is, C*D=E. If E is encoded in 8421, C is encoded in 8421 or 5421, and D is encoded in 8421 or 5421, etc., E can be directly read from the interchange of the codes to get the product.

[0121] It should be understood that the order of execution of the steps in the above embodiment does not necessarily mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiment of the present invention.

[0122] In one embodiment, a BCD code processing device based on decimal multiplication is provided, and the BCD code processing device based on decimal multiplication corresponds one-to-one to the BCD code processing method based on decimal multiplication in the above embodiment. Figure 7 As shown, the BCD code processing device based on decimal multiplication includes a factor acquisition module 10, a first BCD code determination module 20, a second BCD code determination module 30 and a final product determination module 40. Each functional module is described in detail as follows:

[0123] The factor acquisition module 10 is used to obtain the multiplicand and the multiplier, where the multiplicand and the multiplier are decimal numbers;

[0124] The first BCD code determination module 20 is used to determine the BCD code corresponding to the multiplicand, the BCD code includes 8421BCD code and 5421BCD code, and determine the 5221BCD code corresponding to the multiplier.

[0125] The second BCD code determination module 30 is used to determine whether the BCD code used by the multiplicand is 8421BCD code or 5421BCD code when the multiplicand is multiplied by each bit according to the bit number of the 5221BCD code of the multiplier;

[0126] The final product determination module 40 is used to obtain the partial products corresponding to the number of bits of the multiplicand and the multiplier, and add the partial products to determine the final product corresponding to the multiplicand and the multiplier. The final product is 8421BCD code. If there is a carry from one group to the next group during the addition, the number 0110 of the 8421BCD code is added to the group.

[0127] In some embodiments, the second BCD code determination module 30 includes:

[0128] The grouping submodule is used to divide the multiplicand into groups of four bits from low to high.

[0129] The first digit determination submodule is used to determine that when the multiplicand is multiplied by the digit corresponding to the first digit, the BCD code used by the multiplicand is 8421BCD code if the digit of the 5221BCD code of the multiplier is the first digit.

[0130] The second digit determination submodule determines that if the digit of the 5221BCD code of the multiplier is the second digit, then when the multiplicand is multiplied by the number corresponding to the second digit, the BCD code used by the multiplicand is the 5421BCD code.

[0131] The third digit determination submodule determines that if the digit of the 5221BCD code of the multiplier is the third digit, then when the multiplicand is multiplied by the digit corresponding to the third digit, the BCD code used by the multiplicand is the 5421BCD code.

[0132] The fourth digit determination submodule determines that if the digit of the 5221BCD code of the multiplier is the fourth digit, then when the multiplicand is multiplied by the digit corresponding to the fourth digit, the BCD code used by the multiplicand is the 8421BCD code.

[0133] In some embodiments, the final product determination module 40 includes:

[0134] The clearing submodule is used to clear the original partial product.

[0135] The new partial product forming submodule is used to determine whether the multiplicand is added to the original partial product based on the last digit value of the multiplier, and to shift the original partial product right by one digit to form a new partial product.

[0136] The multiplier right shift submodule is used to shift the multiplier right by one position, use the second lowest position as the new last position value, and leave the highest position of the multiplier vacant to place the lowest position of the partial product.

[0137] The repetitive execution submodule is used for repeatedly executing the step of determining whether the multiplicand is added to the original partial product based on the last digit value of the multiplier until after the highest digit of the multiplier.

[0138] The final product determination submodule is used for taking the partial product as the high-order value of the final product and taking the multiplier as the low-order value of the final value.

[0139] In some embodiments, the final product determination module 40 includes:

[0140] The original partial product is not right-shifted submodule, which is used for not right-shifting the original partial product by one position when it is determined that the last digit value of the multiplier is the third digit of the initial multiplier.

[0141] The multiplier emptying submodule is used to shift the multiplier right by one position, taking the second lowest position as the new last position value, and emptying the highest position of the multiplier without placing the lowest position of the partial product.

[0142] In an exemplary embodiment, the BCD code processing device based on decimal multiplication further includes:

[0143] The fourth bit value determination submodule is used to determine that the fourth bit value of the 5221BCD code of the multiplier is 1.

[0144] The target multiplicand generation submodule is used to right-shift the multiplicand by three bits, convert the highest bit value 1 of each group into a value 0, and then add the value 0101 of the 8421BCD code to the corresponding converted group to generate the target multiplicand, which is used to add the target multiplicand to the original partial product.

[0145] In an exemplary embodiment, the BCD code processing device based on decimal multiplication further includes:

[0146] The multiplier value 5 acquisition module is used to obtain the 8421BCD code of the multiplicand when the multiplier value is 5.

[0147] The first result product determination module is used to right-shift the multiplicand of the 8421BCD code by three bits and use the right-shifted multiplicand as the first result product of the multiplicand and the multiplier, and the code system of the first result product is 5421BCD code.

[0148] In an exemplary embodiment, the BCD code processing device based on decimal multiplication further includes:

[0149] The multiplier value 2 acquisition module determines the 5421BCD code of the multiplicand when the multiplier value is 2.

[0150] The second result product determination module is used to right-shift the multiplicand of the 5421BCD code by one bit, and use the right-shifted multiplicand as the second result product of the multiplicand and the multiplier, and the code system of the second result product is 8421BCD code.

[0151] For the specific definition of the BCD code processing device based on decimal multiplication, please refer to the definition of the BCD code processing method based on decimal multiplication in the above text, which will not be repeated here. Each module in the above-mentioned BCD code processing device based on decimal multiplication can be implemented in whole or in part by software, hardware and a combination thereof. The above-mentioned modules can be embedded in or independent of the processor in the device in the form of hardware, or can be stored in the memory in the device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.

[0152] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 8 As shown. The computer device includes a processor, a memory, a network interface and a database connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile medium and an internal memory. The non-volatile medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile medium. The database of the device is used for data related to a BCD code processing method based on decimal multiplication. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a BCD code processing method based on decimal multiplication is implemented.

[0153] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the BCD code processing method based on decimal multiplication in the above embodiment is implemented. For example, Figure 2Alternatively, when the processor executes the computer program, the functions of each module / unit of the BCD code processing device based on decimal multiplication in the above embodiment are realized, for example Figure 7 The functions of the modules 10 to 40 are shown in Figure 1. To avoid repetition, they will not be described in detail here.

[0154] In one embodiment, a computer readable medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the BCD code processing method based on decimal multiplication in the above embodiment is implemented, for example Figure 2 Alternatively, when the computer program is executed by the processor, the functions of each module / unit in the BCD code processing device based on decimal multiplication in the above device embodiment are realized, for example Figure 7 The functions of the modules 10 to 40 are shown in Figure 1. To avoid repetition, they will not be described in detail here.

[0155] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments of the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).

[0156] Those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be distributed and completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above.

[0157] The above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit the same. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention.

Claims

1. A BCD code processing method based on decimal multiplication, characterized in that: The BCD code processing method based on decimal multiplication includes: Obtaining a multiplicand and a multiplier; wherein the multiplicand and the multiplier are both decimal numbers; Determine a BCD code corresponding to the multiplicand and a 5221BCD code corresponding to the multiplier; the BCD code corresponding to the multiplicand includes an 8421BCD code and a 5421BCD code; Determining, according to the number of bits of the 5221BCD code of the multiplier, whether the BCD code used by the multiplicand is an 8421BCD code or a 5421BCD code when the multiplicand is multiplied by each bit; Obtain partial products corresponding to the number of bits of the multiplicand and the multiplier, and add the partial products to determine a final product corresponding to the multiplicand and the multiplier; the final product is 8421BCD code; wherein, if there is a carry from one group to the next during the addition, then add the number 0110 in 8421BCD code to the group.

2. The BCD code processing method based on decimal multiplication according to claim 1, wherein: Determining, according to the number of bits of the 5221BCD code of the multiplier, whether the BCD code used by the multiplicand is an 8421BCD code or a 5421BCD code when the multiplicand is multiplied by each bit, specifically includes: Divide the multiplicand into groups of four from the lowest digit to the highest digit; If the number of digits of the 5221BCD code of the multiplier is the first digit, determining that when the multiplicand is multiplied by the digit corresponding to the first digit, the BCD code used by the multiplicand is the 8421BCD code; If the number of digits of the 5221BCD code of the multiplier is the second digit, determining that when the multiplicand is multiplied by the number corresponding to the second digit, the BCD code used by the multiplicand is the 5421BCD code; If the number of digits of the 5221BCD code of the multiplier is the third digit, determining that when the multiplicand is multiplied by the number corresponding to the third digit, the BCD code used by the multiplicand is the 5421BCD code; If the number of digits of the 5221BCD code of the multiplier is the fourth digit, it is determined that when the multiplicand is multiplied by the number corresponding to the fourth digit, the BCD code used by the multiplicand is the 8421BCD code.

3. The BCD code processing method based on decimal multiplication according to claim 2, wherein: Obtaining partial products corresponding to the number of bits of the multiplicand and the multiplier, and adding the partial products to determine a final product corresponding to the multiplicand and the multiplier, comprising: Clear the original partial volume to zero; determining whether the multiplicand should be added to the original partial product based on the last digit value of the multiplier, and shifting the original partial product right by one digit to form a new partial product; Shift the multiplier right by one position, set the second lowest bit as the new last bit value, and leave the highest bit of the multiplier vacant to place the lowest bit of the partial product; Repeat the step of determining whether the multiplicand is added to the original partial product based on the last digit value of the multiplier until, based on the highest digit of the multiplier, the partial product is used as the high-order value of the final product and the multiplier is used as the low-order value of the final product.

4. The BCD code processing method based on decimal multiplication according to claim 3, wherein: Obtaining partial products corresponding to the number of bits of the multiplicand and the multiplier, and adding the partial products to determine a final product corresponding to the multiplicand and the multiplier, further comprising: When the last digit of the multiplier is the third digit of the initial multiplier, the original partial product is not shifted right by one digit; The multiplier is shifted right by one position, and the second lowest position is used as the new last position value. The highest position of the multiplier is left vacant and the lowest position of the partial product is not placed.

5. The BCD code processing method based on decimal multiplication according to claim 2, wherein: If the number of digits of the 5221BCD code of the multiplier is the fourth digit, after determining that the BCD code used by the multiplicand when the multiplicand is multiplied by the number corresponding to the fourth digit is the 8421BCD code, determining, based on the number of digits of the 5221BCD code of the multiplier, whether the BCD code used by the multiplicand when the multiplicand is multiplied by each digit is the 8421BCD code or the 5421BCD code further includes: Determine that the value of the fourth bit of the 5221BCD code of the multiplier is 1; The multiplicand is shifted right by three bits, the value 1 of the highest bit of each group is converted into a value 0, and then the value 0101 of the 8421BCD code is added to the corresponding converted group to generate a target multiplicand, which is used to add the target multiplicand to the original partial product.

6. The BCD code processing method based on decimal multiplication according to claim 1, characterized in that: The BCD code processing method based on decimal multiplication also includes: When the multiplier value is 5, the 8421BCD code of the multiplicand is determined; The multiplicand of the 8421BCD code is right-shifted by three bits, and the multiplicand after the right shift is used as a first result product of the multiplicand and the multiplier, wherein the coding system of the first result product is the 5421BCD code.

7. The BCD code processing method based on decimal multiplication according to claim 1, characterized in that: The BCD code processing method based on decimal multiplication also includes: When the multiplier value is 2, determining the 5421BCD code of the multiplicand; The multiplicand of the 5421BCD code is right-shifted by one bit, and the multiplicand after the right shift is used as the second result product of the multiplicand and the multiplier, wherein the coding system of the second result product is the 8421BCD code.

8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the BCD code processing method based on decimal multiplication according to any one of claims 1 to 7 is implemented.