BCD数计算

BCD码和十进制数和十六进制数关系 unsigned char ucBCDdata[10] = {0x11,0x22,0x33,0x44,0x55,0x55,0x66,0x77}; unsigned char ucHEXdata11 = 0,ucHEXdata[10] = {0}; unsigned int uiHEXdata = 0,uiHEXdata11 = 0; unsigned long int ulHEXdata =... 阅读详情

 

BCD Arithmetic, a tutorial

Part of the Arithmetic Tutorial Collection
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

Copyright © 1999, Douglas. W. Jones, with major revisions made in 2002. This work may be transmitted or stored in electronic form on any computer attached to the Internet or World Wide Web so long as this notice is included in the copy. Individuals may make single copies for their own use. All other rights are reserved.

Index

Rated as a top 50 site by Programmer's Heaven as of Feb 2002.

Introduction

Binary coded decimal arithmetic has fallen out of favor among modern hardware designers, and it is poorly supported in most modern programming languages, yet it is still occasionally appropriate. For example, when a numeric field of a record in a text file must be incremented, the methods presented here will be significantly faster than converting the textual value to a binary integer, incrementing, and then converting back to text.

For programmers with a devious sense of humor, these methods can be a very effective way to obfuscate code in languages such as C. These techniques are also historically significant. The DEC (now Compaq) Alpha architecture and the more recent Intel MMX extensions to the 80x86 architecture both supporting manipulation of vectors of small objects such as pixels packed into 64-bit words; the motive for this can be found in the much older ideas described here.

In the following sections, all arithmetic is assumed to be done in 32 bit registers (the algorithms are easily adapted to other word lengths), and neither carry out nor overflow are deemed significant. The code written for clarity, using C notation for operators and constants, with named temporary variables whenever a subexpression in the computation is cited in the text. Practical implementations will very likely use far fewer temporary variables.

All of the number representations discussed here are unsigned, although the subtraction operation rests on the use of ten's complement arithmetic, and this, in turn, suggests the use of the ten's complement operation for negation. In that case, number with a most significant digit greater than 5 can be interpreted as negative numbers.

For unsigned decimal numbers (or for 10's complement numbers with the same sign), the conventional unsigned binary comparison operators all remain applicable with these decimal represenations. Thus, if A and B are unsigned decimal numbers, and if > is the conventional unsigned greater-than operator for binary numbers, A>B will yield the correct results for comparing these numbers.

The programmer interested in efficient BCD to Binary conversion should also check out the code in appendix I.5 of the paper "Superoptimizer -- A Look at the Smallest Program" by Henry Massalin, Proc. Second Int. Conf. on Arch. Support for Prog. Lang. and Op. Sys. (ASPLOS II) published as Computer Architecture News 15 , 5 (Oct. 1987).

 


BCD Represenations

Binary coded decimal numbers may be represented in a number of ways. The most obvious is packed BCD, where each decimal digit is represented by a 4 bit field, and the digits are packed consecutively into a computer word. This scheme allows 4 digits to be packed into a 16 bit word, or 8 digits into a 32 bit word, as shown below.

    B31                             B15                            B0
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
| D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |

In addition to its efficiency, this format is useful because it is compatable with the use of hexidecimal I/O routines. Traditionally, packed BCD was viewed as requiring the use of special hardware to do BCD arithmetic, but in fact, it is possible to add two packed BCD numbers using a short sequence of conventional binary and logical operators.

Many early computers used 6-bit BCD codes, where each BCD digit was padded to 6 bits. This was compatable with the 36, 48 and 60 bit words used by many computers in the 1950's and 1960's, and on both the 36-bit IBM 704-709 series of machines (up through the 7044 and 7094) and 60-bit CDC 6600 series, this format was used to do BCD arithmetic without any special hardware support. On a modern 16 or 32 bit machine, this allows 3 or a bit more than 5 decimal digits per word, respectively.

    B31                             B15                            B0
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
| D5|0 0| D4 |0 0| D3 |0 0| D2 |0 0| D1 |0 0| D0 |

In the 32 bit format, productive use can be made of the fractional digit D5 for carry detection and propagation in extended precision arithmetic operations.

It should be noted that in most historically important 6-bit BCD collating sequences, all numerals other than zero were represented as shown above, while zero was sometimes represented by the binary code 1010, allowing the 6-bit code 000000 to be used for space. Ones in the two most significant bits of each 6-bit byte were used in the codes for letters and punctuation marks. See material on punched card codes for more detail on this subject.

The methods discussed here can be extended to other padding systems in obvious ways. For example, 6 5-bit fields can be packed into a 32-bit word, with one bit of padding between BCD digits. Alternately, 3 bits of padding can be added between digits, so that a 32-bit word holds 4 complete 7-bit fields, plus 4 bits that can be used for a 5th BCD digit.

Padding each BCD digit to fill an 8 bit byte is quite practical, but this inefficient representation is not particularly interesting except in the special case where each digit is directly represented by its ASCII code , as follows:

    B31                             B15                            B0
|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _|
|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|_|
|0 0 1 1| D3 |0 0 1 1| D2 |0 0 1 1| D1 |0 0 1 1| D0 |

Of course, the same approach can be used for EBCDIC, using 0xF for a pad digit instead of 0x3 . It is quite practical to do arithmetic operations directly on all of these representations!

 


Packed BCD Arithmetic

Validity Checking

The least significant 7 digits of a packed BCD number may be tested for validity as follows:

    valid(a)
t1 = a + 0x06666666
t2 = a ^ 0x06666666
t3 = t1 ^ t2
t4 = t3 & 0x11111110
if t4 nonzero, a is invalid

This code deliberately ignores D7, the most significant digit, because the arithmetic operators presented here allow this digit to hold values up to 15. To understand this code, note that binary addition of 6 to each digit, to produce t1 , will cause any digit with a value greater than 9 to generate a carry into the next higher digit.

t2 is similar to t1 , in the sense that exclusive-oring is similar to adding. The two will be equal in bits where there was no carry in to that position, but they will differ in bits where there was a carry in. Therefore, t3 holds a one wherever there was a carry into a bit of t1 , and t4 holds a 1 wherever there was a carry into a BCD digit of t1 . Since the addition used to produce t1 should not produce such carries for a valid BCD number, t4 should be zero!

    valid(a)
t1 = a + 0x06666666
t2 = t1 ^ a
t3 = t2 & 0x11111110
if t3 nonzero, a is invalid

The above improvement was suggested by John Mertus at Brown University; Here, note that adding 6 to a 4-bit nibble of a produces a carry out of that nibble if the nibble is invalid, but also, adding 6 does not change the least significant bit. By exclusive oring the result in t1 with a to make t2 , the least significant bit of each nibble is compared with the original. Finally, we ignore all the other bits and demand that all the least significant bits be zero, indicating no carry from the previous bit positions.

Antoine Schweitzer-Chaput suggested an alternative validity check to me. Note that all BCD digits of the form 0xxx are valid, as are digits of the form x00x. Therefore, if d is a BCD digit, we can test it for validity with:

   valid(d)
if (d & 0x8) is zero or (d & 0x6) is zero

Extending this to packed BCD is a fun challenge.

 

Addition

The code to add two BCD numbers must solve the problem of propagating carries from one BCD digit to the next, and the logic for doing so rests on many of the mechanisms introduced above.

    add(a,b)
t1 = a + 0x06666666
t2 = t1 + b
t3 = t1 ^ b
t4 = t2 ^ t3
t5 = ~t4 & 0x11111110
t6 = (t5 >> 2) | (t5 >> 3)
return t2 - t6

Here, the addition used to form t1 should not produce any carries, since we assume that t1 is valid. The addition used to form t2 will produce a carry exactly when the decimal addition of two digits in the operands would produce a carry, and these are the carries we are concerned with.

In t2 , the digits in each position that produced a carry will have the correct value, but the digits in positions that did not produce a carry will contain an excess 6. The problem, then, is to remove the extra 6 from each digit that did not generate a carry.

Note that t2 and t3 differ wherever there was a carry, so t4 records all carries into positions in the sum. Therefore, t5 holds the inverse of each of the 7 carries between successive decimal digits of the sum. This bit pattern is used to generate t6 , where each digit is either 6 where the corresponding digits of the sum did not generate a carry or 0 where they did. Subtracting this from t2 produces the correct BCD sum.

Note that the most significant digit of the sum will exceed 9 if there should have been a carry out of that position. Furthermore, there is no easy way to detect this carry! Out of range values in the high digit may be of some limited use, but in general, the top BCD digit should only be used to accumulate carrys out of 7-digit BCD operands. If its use is limited in this way, the numbers will always be positive and will never produce a 2's complement overflow.

 

Subtraction

To subtract two numbers, 10's complement addition should be used. To compute the 10's complement of a number, subtract it digit-by-digit from 99999999 (decimal) and then add 1, as follows:

    tencomp(a)
t1 = 0xF9999999 - a
return add( t1, 0x00000001 )

Here, t1 is (mostly) the 9's complement of the argument, except that the topmost digit is the 15's complement because of the redundancy allowed in that digit position. There is room for optimization in this code! As a first step, the code for addition has been substituted into place (with appropriate variable renaming).

    tencomp(a)
t1 = 0xF9999999 - a
t2 = t1 + 0x06666666
t3 = t2 + 0x00000001
t4 = t2 ^ 0x00000001
t5 = t3 ^ t4
t6 = ~t5 & 0x11111110
t7 = (t6 >> 2) | (t6 >> 3)
return t3 - t7

This reduces to the following obscure bit of code, with variables renamed again:

    tencomp(a)
t1 = 0xFFFFFFFF - a
t2 = - a
t3 = t1 ^ 0x00000001
t4 = t2 ^ t3
t5 = ~t4 & 0x11111110
t6 = (t5 >> 2) | (t5 >> 3)
return t2 - t6

6-bit BCD Arithmetic

Validity Checking

All 5 full digits of a 6-bit BCD number may be tested for validity as follows:

    valid(a)
t1 = a + 006666666666
t2 = t1 & 006060606060
if t2 = 006060606060, a is valid

To understand this code, note that binary addition of 066 to each digit, to produce t1 , will cause any digit with a value greater than 9 to generate a carry into the next higher digit. The lower 6 forces a carry out of any digit greater than 9, while the higher 6 sets the pad bits and allows the carry to propagate up to the next higher digit position.

t2 holds just the pad bits in the result from t1 . Where no carry was propagated in the computation of t1 , these will be set, while where a carry was propagated through the padding, they will be reset. A valid 6-bit BCD number should not have generated any carry, so all of the pad bits should be set!

 

Addition

The code to add two 5-digit 6-bit BCD numbers must solve the problem of propagating carries from one BCD digit to the next, and the logic for doing so rests on the mechanisms just introduced:

    add(a,b)
t1 = a + b + 006666666666
t2 = t1 & 006060606060
return t1 - (t2 >> 3)

Here, the addition used to form t1 adds an extra 6 to each BCD digit, forcing a carry out of that digit if the sum exceeds 9, and the same constant also includes ones in each pad bit in order to force this cary to propagate up to the next higher digit.

In t1 , the digits in each position that produced a carry will have the correct value, but the digits in positions that did not produce a carry will contain an excess 6. The problem, is to remove this 6 from each digit that did not generate a carry.

t2 contains just the pad bits from the sum. For those digits that did not produce a carry, the pad bits will still be set to one. For those digits that produced a carry, the pad bits will be set to zero by the propagagion of the carry.

Shifting t2 3 places right produces a 6 in each digit position that did not generate a carry and zero elsewhere. Subtracting this from t1 produces the required correction!

A carry out from the 5-digit BCD sum will appear in partial digit, D5, that occupies the topmost 2 bits of the 32 bit number.

 

Subtraction

To subtract two numbers, 10's complement addition should be used. To compute the 10's complement of 5-digit 6-bit BCD number, subtract it digit-by-digit from 99999 (decimal) and then add 1, as follows:

    tencomp(a)
t1 = 001111111111 - a
return add( t1, 000000000001 )

Here, t1 is the 9's complement of the argument (note that 11 octal is 9 decimal). There is considerable room for optimization in this! Substituting the definition of add and renaming the variables to avoid collision, we get:

    tencomp(a)
t1 = 001111111111 - a
t2 = t1 + 000000000001 + 006666666666
t3 = t2 & 006060606060
return t2 - (t3 >> 3)

Rearranging terms and renaming temporaries gives:

    tencomp(a)
t1 = (001111111111 - a)
+ 000000000001
+ 006666666666
t2 = t1 & 006060606060
return t1 - (t2 >> 3)

Which simplifies to:

    tencomp(a)
t1 = 010000000000 - a
t2 = t1 & 006060606060
return t1 - (t2 >> 3)

ASCII Arithmetic

Validity Checking

To verify that a 4-digit ASCII string contains only valid BCD codes, techniques similar to those used for packed BCD and 6-bit BCD can be used:

    valid(a)
t1 = a + 0xC6C6C6C6
t2 = t1 & 0xF0F0F0F0
if t2 = 0xF0F0F0F0, a is valid

To understand this code, note that binary addition of 0xC6 to each digit, to produce t1 , will cause any digit with a value greater than 9 to generate a carry into the next higher digit. The lower 6 forces a carry out of any digit greater than 9, while the higher 0xC sets those pad bits which were not already set in the ASCII representation of the digit, thus allowing the carry to propagate up to the next higher digit position.

t2 holds just the pad bits from t1 . Where no carry was propagated in the computation of t1 , these will be set, while where a carry was propagated, they will be reset. A valid 6-bit BCD number should not have generated any carry, so all pad bits should be set!

Validity checking is more complex if blank and zero are to be interchangable, and more complex still if only leading blanks are allowed. On the other hand, oring 0x10101010 with a potential number converts all blanks to zeros, while also converting certain punctuation marks to other numerals. In certain applications, this may be a reasonable way to deal with blanks.

 

Addition

The code to add two 4-digit ASCII numbers must solve the problem of propagating carries from one BCD digit to the next, and the logic for doing so rests on the mechanisms just introduced:

    add(a,b)
t1 = a + b + 0x96969696
t2 = t1 & 0x30303030
t3 = t1 - (t2 >> 3)
return (t3 & 0x0F0F0F0F) | 0x30303030

Here, the addition used to form t1 adds an extra 6 to each BCD digit, forcing a carry out of that digit if the sum exceeds 9. In addition, it sets those pad bits which would not already be set by the padding included in ASCII for each character. This forces carry propagation up to the next higher digit.

In t1 , the digits in each position that produced a carry will have the correct value, but the digits in positions that did not produce a carry will contain an excess 6.

t2 contains the two least significant bits of the padding from the sum; these bits will be 1 where no carry was propagated, so they can be shifted to subtract the excess 6 from the adjacent digit of the sum. This corrected sum, in t3 still contains the incorrect values in the pad fields. No matter what we do, it seems to take two extra binary operations to restore the pad fields to their proper values.

The carry out from the 4-digit ASCII sum can be extracted from the pad bits of any of the temporary variables used above, so no digits are wasted in extended precision ASCII arithmetic.

By all means, if your purpose is to write obfuscated code, and if your programming language allows it, substitute ASCII literals for the hex constants wherever possible, as follows:

    add(a,b)
t1 = a + b + 0x96969696
t2 = t1 & '0000'
t3 = t1 - (t2 >> 3)
return (t3 & 0x0F0F0F0F) | '0000'

 

Subtraction

To subtract two numbers, 10's complement addition should be used. To compute the 10's complement of a number, subtract it digit-by-digit from 9999 (decimal) and then add 1, as follows:

    tencomp(a)
t1 = 0x69696969 - a
return add( t1, 0x30303031 )

Here, t1 is the 9's complement of the argument; the tricky aspect in this case is that the pad bits of the argument are nonzero, so the constant 9999 must be padded strangely to create the correct results. In any case, there is considerable room for optimization in this code! Substituting the code for addition and renaming temporaries gives:

    tencomp(a)
t1 = 0x69696969 - a
t2 = t1 + 0x30303031 + 0x96969696
t3 = t2 & 0x30303030
t4 = t2 - (t3 >> 3)
return (t4 & 0x0F0F0F0F) | 0x30303030

Combining terms, renaming, and simplifing the result gives the following strange bit of code:

    tencomp(a)
t1 = 0x20202020 - a
t2 = t1 & 0x30303030
t3 = t1 - (t2 >> 3)
return (t3 & 0x0F0F0F0F) | 0x30303030

Of course, if your purpose is to write obfuscated code, by all means substitute ASCII literals for the hex constants wherever possible, creating:

    tencomp(a)
t1 = ' ' - a
t2 = t1 & '0000'
t3 = t1 - (t2 >> 3)
return (t3 & 0x0F0F0F0F) | '0000'

 

Hardware Support

Much of the complexity of the above code is imposed by computations that determine the carry out of each digit of the BCD sum. Hardware that allows the carry propagation from bit to bit of the adder to be interrupted at selected points can greatly speed these computations. Both the DEC (later Compaq) Alpha and the Intel MMX extensions to the 80x86 family provide for this, allowing 64 bit words to be divided into many subfields, with carry propagation from field to field interrupted, and with the carries captured in a form allowing their manipulation. These facilities are not exposed to the high level language programmer, but they are used intensively in carefully handcrafted assembly-language routines for common vector operations such as those involved in pixel manipulation of graphics images.

 

微型计算机接口与技术答案,《微机原理与接口技术》课后习题答案 第一章1.在计算机中为什么使用二进制数存储数据而不使用十进制数存储数据? 答:计算机是由大量的电子器件组成的,在这些电子器件中,电路的通和断、电位的高和低,用两个数字符号“1”和“0”分别表示容易实现。同时二进制的运算法则也很简单,因此,在计算机内部通常用二进制代码来作为内部存储、传输和处理数据。 2.完成下列数制之间的转换。(1)01011100B=92D (2)0.... 阅读详情

相关推荐

【obj To 3DTiles 进阶实战】 从零配置地理坐标系与扩展属性元数据

本文详细解析了如何将OBJ模型转换为3DTiles格式,重点介绍了地理坐标系配置与属性元数据扩展的实战技巧。通过obj23dtiles工具,开发者可以精准定位模型经纬高坐标,并添加结构化属性表,实现城市规划模型在数字孪生平台的高效应用。

weixin_27215337的博客 367

BCD加法器

BCD加法器 首先简单介绍一下8421BCD码:它是由4位二进制数0000(0)到1111(15)16种组合的前10种组合,即0000(0)~1001(9)构成,其余6种组合无效。其编码中每位的值都是固定数,称为位权。b3权为2^3=8,b2位权为2 ^2=4,b1位权为2,b0位权为1,因此称8421BCD码。 对于两个4位BCD码相加所得的结果超过1001(9),则将所得数加0110(6),并产生一个进位。 1.4位BCD加法 module BCD_adder4( input [3:0] a, inpu

qq_38318540的博客 1万+

分享一下使用Xilinx FPGA驱动MIPI DSI LCD屏的心路历程

分享一下调试用Xilinx FPGA驱动MIPI DSI LCD屏的心路历程,看到的朋友们,可以避免继续踩坑。

haoxingheng的专栏 5014

什么是 BCD(二进制编码的十进制)

BCD 是一位十进制数,由代表 0 到 9 的四位二进制数字表示。 当寄存器值以十六进制表示时,可以原样读取为十进制数,这对于处理十进制数的函数来说非常方便。 二进制数的 4 位可以表示为 0 到 15,但只有低 10 位被视为有效数字。 例如,假设运算的结果是十进制数“37”。 由于它是作为二进制数存储在实际寄存器中的,“0010 0101”就是寄存器值。 另一方面,在使用集成开发工具或液晶显示器显示人类可以确认的数​​字时,十六进制数比二进制数更容易看清,因此以十六进制“25”显示。 但是,这样做很

编程老王 3万+

【ARM CoreLink 系列 4 -- NIC-400 控制器详细介绍】

正常情况下,一个NIC的实现,可以包含一百多个master和几十个slave,每个master和每个slave都会有一些寄存器,这些寄存器可以被 programming,实际实践中就会对 AMIB 或者 ASIB 或者 IB,当它需要具有 programming的时候,给它指定一个node number。为什么指定Node Number呢?首先,从CPU的角度,它需要有一个1M对齐的地址空间,在这1M地址空间上,对每个ASIB或者AMIB这样的接口给它一个node number以后,

CodingCos的博客 5242

【数据集】中国大气污染物数据集CHAP(1km空间分辨率)-韦晶团队

中国大气污染物数据集CHAP(1km空间分辨率)-韦晶团队

WW、forever的博客 2598

BCD数(非原创,摘抄而来)

那么,这里就存在一个问题,我们使用计算器,是输入的为十进制数 25,但是计算机使用二进制数来处理信息,那么就得将 25 (D)转化成 0001 1001 (B),同样计算 25 + 25时,计算机也是处理二进制的25相加,而运算结果 0011 0010(B)还是的需要转化为 十进制 50,展示给人看。前人想出了,一种比较适合十进制系统的二进制编码的特殊形式,即将1位十进制的0~9这十个数字分别用4位二进制的组合来表示,在此基础上可按位对任意十进制数进行编码。那么,计算次数越多,这损失的效率越大。

xipan_的博客 1153

Arduino与震动马达模块握手

震动马达模块采用采用高品质手机震动马达,适用于震动感互动产品的制作,可穿戴智能设备震动提醒,适合作为非可听指示器的小型振动马达。当输入为高电平时电动机会震动,就像你的静音模式的手机一样。

vor234的博客 5847

BCD数是用一个字节来表达两位十进制的数,每四个比特表示一位。所以如果一个BCD数的十六进制是0x12,它表达的就是十进制的12。但是小明没学过BCD,把所有的BCD数都当作二进制数转换成十进制输出了

BCD数是用一个字节来表达两位十进制的数,每四个比特表示一位。所以如果一个BCD数的十六进制是0x12,它表达的就是十进制的12。但是小明没学过BCD,把所有的BCD数都当作二进制数转换成十进制输出了。于是BCD的0x12被输出成了十进制的18了! 现在,你的程序要读入这个错误的十进制数,然后输出正确的十进制数。提示:你可以把18转换回0x12,然后再转换回12。 实际上题目就是让你把这个数转化为16进制的数。但是一定不能把,num1*10+num2拿出来,否则就会部分任务点错误。原因我也不知道,知道的大佬

lhvgod的博客 5768

YOLOv5源码逐行超详细注释与解读(3)——训练部分train.py

全网最详细的YOLOv5项目源码解读之训练部分train. py。全文近5万字!代码逐行注释,逐段讲解,小白入门必备!

路人贾的博客 3万+

基于多智能体的自动化公司调研系统

在当今竞争激烈的商业世界中,了解公司的详细信息对于投资者、合作伙伴和研究机构等具有重要意义。传统的公司调研方式往往需要耗费大量的人力、物力和时间,且容易出现信息不全面、不准确等问题。基于多智能体的自动化公司调研系统的目的是利用多智能体技术,实现公司调研的自动化和智能化,提高调研的效率和准确性。本系统的范围涵盖了公司基本信息收集、市场竞争力分析、财务状况评估等多个方面。本文将按照以下结构进行组织:首先介绍系统的核心概念和相关联系,包括多智能体系统的原理和架构;

架构师的AI之路,分享AI应用开发架构的学习与实践。 965

7-4 BCD解密 (10分)

7-4 BCD解密 (10分) BCD数是用一个字节来表达两位十进制的数,每四个比特表示一位。所以如果一个BCD数的十六进制是0x12,它表达的就是十进制的12。但是小明没学过BCD,把所有的BCD数都当作二进制数转换成十进制输出了。于是BCD的0x12被输出成了十进制的18了! 现在,你的程序要读入这个错误的十进制数,然后输出正确的十进制数。提示:你可以把18转换回0x12,然后再转换回1...

汪汪的博客 3586

MFC实现简单UDP通信(附完整源码)

MFC实现简单UDP通信(附完整源码)

希望我的博客,能帮上你解决学习中工作中所遇到的问题 1110

然后是几点、BCD解密、计算符号函数的值

7-14 然后是几点 (15 分) 有时候人们用四位数字表示一个时间,比如1106表示11点零6分。现在,你的程序要根据起始时间和流...

杨丙寅 106

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

十进制,BCD数怎样转8421BCD码

BCD数是一种采用4位二进制数表示1位十进制数(0~9)而得到的数。         例如:89的BCD码为(相当于将89中的8和9分别转为二进制,而可以得出BCD码): 8 9 0101 1001         则可以得出89的BCD数为:0101 1001         接下来就是将此BCD码转为8421BCD码了,其实很简单,将每个分别转

专注于C#核心技术 2万+

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

浅谈BCD码--数在计算机中的表示方法及编码

今天上午,米老师给我们浅析了BCD码,那么什么是BCD码呢,接下来我把自己的认识和网上的资料整理分享给大家。   BCD码(Binary-Coded Decimal?)亦称二进码十进数或二-十进制代码。用4位二进制数来表示1位十进制数中的0~9这10个数码。是一种二进制的数字编码形式,用二进制编码的十进制代码。BCD码这种编码形式利用了四个位元来储存一个十进制的数码,使二进制和十进制之间的转换得

〡TonyべLC 的Blog 3047

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

二进制与BCD码转换

#define WORD_MSB(x)    *((unsigned char *)&x+1) #define WORD_LSB(x)    *((unsigned char *)&x) unsigned int saveBCD;//二进制数转换为压缩BCD数,结果存入saveBCD中 int BinToBcd(unsigned char val) {     unsig

haomcu的专栏 5142

计算机的基础知识

计算机基础知识

weixin_52582573的博客 912

【PTA】基础编程题7-4 BCD解密

BCD数是用一个字节来表达两位十进制的数,每四个比特表示一位。所以如果一个BCD数的十六进制是0x12,它表达的就是十进制的12。但是小明没学过BCD,把所有的BCD数都当作二进制数转换成十进制输出了。于是BCD的0x12被输出成了十进制的18了!现在,你的程序要读入这个错误的十进制数,然后输出正确的十进制数。提示:你可以把18转换回0x12,然后再转换回12。

King_lxh的博客 1142

计算分段函数+BCD解密---PTA实验C++

这里的cout

hetupyou的博客 456

数电、计算机基础所学的一些“码”

一、原码、补码、反码 1.原码: 第一位为符号位,1为负、0为正。 2、反码: 正数:原码本身 负数:在其原码的基础上,符号位不变,其余各个位取反 3、补码: 正数:原码本身 负数:反码的基础上+1(同样补码求反码+1可得原码)   二、BCD码 1、简介: BCD码(Binary-Coded Decimal‎)亦称二进码十进数或二-十进制代码。用4位二进制数来表示1位十进...

SJLin 839

编程练习

1. 然后是几点 用四位数字表示时间,程序要根据给定的时间和流逝时间计算出终止时间。结果表示为四位数字。 注:第二个数字表示的流逝时间可能大于60,也可能小于0 输入样例:1120 120 输出样例:1320 分析 要先将输入值转为小时和分钟分别保存,要让程序分清小时和分钟 实现代码 scanf_s("%d %d", &time, &period); hour1 = time / 100; min1 = time % 100; 在这里要注意用scanf_s,直接用scanf可能导致

SmileJayNew的博客 522

C:BCD解密

BCD数是用一个字节来表达两位十进制的数,每四个比特表示一位。所以如果一个BCD数的十六进制是0x12,它表达的就是十进制的12。但是小明没学过BCD,把所有的BCD数都当作二进制数转换成十进制输出了。于是BCD的0x12被输出成了十进制的18了! 现在,你的程序要读入这个错误的十进制数,然后输出正确的十进制数。提示:你可以把18转换回0x12,然后再转换回12。 输入格式: 输入在一行中给出一个...

qq_45473923的博客 977

pta模拟题(7-15 BCD解密、7-16 数列求和-加强版、7-17 出租、7-18 反向数相加、7-19 一帮一、7-20 连续因子)

7-15 BCD解密、7-16 数列求和-加强版、7-17 出租、7-18 反向数相加、7-19 一帮一、7-20 连续因子

FlippedSQ的博客 1322

计算机中的信息表示(原码、反码、补码、ASCII码)

我们知道,不管是数字还是字符,在计算机中,都是以二进制编码形式

keyboard not found! Please press F1 to continue. 5965
上一篇: LINUX kernel 导航
下一篇: Reciprocal Multiplication, a tutorial
海之渊
博客等级 码龄19年 15粉丝 31原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值