Questions tagged [bcd]

A binary-coded decimal (BCD) is a method of representing each decimal digit of a number with a fixed number of bits.

Though binary-coded decimal is less efficient memory-wise than 2's complement there are some advantages that result in BCD still being in use today, particularly in databases and applications where monetary and similarly sensitive data types are stored and manipulated.

194 questions
3
votes
1 answer

Converting Unsigned Int to BCD

I have a function to convert uint16_t to BCD. uint16_t uint162BCD(uint16_t value) { uint16_t b_val = 0; unsigned int shift = 0; while (shift / 8 < sizeof(bcd)) { b_val = static_cast(b_val + ((value % 10) <<…
liv2hak
  • 14,472
  • 53
  • 157
  • 270
3
votes
1 answer

How can I avoid losing precision with ftFmtBcd?

The documentation says: TFMTBCDField encapsulates the fundamental behavior common to binary-coded decimal (BCD) fields. BCD values provide greater precision and accuracy than floating-point numbers. BCD fields are often used for storing and…
ventiseis
  • 3,029
  • 11
  • 32
  • 49
3
votes
1 answer

How to divide a BCD by 2 on an 8085 processor?

On an 8085 processor, an efficient algorithm for dividing a BCD by 2 comes in handy when converting a BCD to binary representation. You might think of recursive subtraction or multiplying by 0.5, however these algorithms require lengthy…
3
votes
3 answers

Bit shifting in BCD

I am shifting the bits of a BCD number either left or right to quickly multiply or divide by 2. Here is a quick example of shifting left: void LShift(unsigned char *arg) { int i, carry=0, temp; for(i=2;i>=0;i--) { …
3
votes
2 answers

How can I show the cents with R3 money?

The online documentation promises this probe to-money 123 $123.00 http://www.rebol.com/r3/docs/datatypes/money.html I get this probe to-money 123 $123
Jina.
  • 105
  • 6
3
votes
3 answers

How to decode an unsigned integer into BCD use VHDL

As we can see that,in VHDL ,MOD and REM only can be simulated but can't be synthesized.So how can we get the BCD from an unsigned integer? For example,the integer is 23,how can we get the BCD:0b0010 and 0b0011? Thanks.
user1673133
  • 31
  • 1
  • 1
  • 2
2
votes
1 answer

How convert BCD format to integer in Lua

I need to write a LUA script that can convert a number from a BCD format to an integer. Let's say my initial byte array looks like this: local bcdArray = {0x73, 0x31, 0x30, 0x00} If I understand the BCD format correctly, this array should turn into…
FaceHoof
  • 89
  • 5
2
votes
1 answer

Convert 6/10/12-bit streams to scaled unsigned char/short

In the world of PC's, a byte usually denotes a memory boundary alignment of 8 bits which the computer treats as a single unit. In mini and mainframe computers, longer sequences like 16 and 32 bits (referred to as full words and double words…
GoldenLee
  • 737
  • 2
  • 13
  • 28
2
votes
1 answer

Binary to BCD conversion

I was asked to convert 8 bits binary to 3 digits of BCD. I saw online people use DIV but I do not understand that way at all, why would I divide by #0AH? If I was asked to subtract 16 bits by 16 bits using 2 pairs of 8 bit registers, do I need to…
Lostdawn
  • 61
  • 1
  • 4
2
votes
2 answers

Convert amount (int) to BCD

I need to convert an Int left padded 6 bytes (amount) to a BCD in Python. int = 145 expect = "\x00\x00\x00\x00\x01\x45" The closest I come is with this code (but it needs to loop in byte pair): def TO_BCD(value): return chr((((value / 10) <<…
JayC
  • 135
  • 1
  • 2
  • 11
2
votes
2 answers

Adding 2 bcd numbers-mips

I'm trying to add 2 numbers that are stored in 2 registers. each number is in bcd format and has 8 digits. I'm wondering if I have a better way then just work on every 4 bits at a time. This is what I started: .text main: addi…
sara
  • 129
  • 1
  • 9
2
votes
2 answers

ISO 8583 - How are BCD Values Calculated For Fields With Subfields?

Can anyone answer how BCD data is usually calculated for fields what have subfield values? I don't mean in terms of code, as I have that part nailed down. What I mean is say I have field X, which is to be sent containing data for 5 sub values. The…
Mike K
  • 45
  • 1
  • 9
2
votes
2 answers

How can i store 2 numbers in a 1 byte char?

I have the question of the title, but If not, how could I get away with using only 4 bits to represent an integer? EDIT really my question is how. I am aware that there are 1 byte data structures in a language like c, but how could I use something…
papiro
  • 2,158
  • 1
  • 20
  • 29
2
votes
2 answers

Reset output after run

I'm working on a small project to learn VHDL. Currently I'm working on a BCD converter (converting a binary to its BCD number). But I got stuck when implementing the testbench. It doesn't reset the output after the patterns got applied. My VHDL code…
CRoemheld
  • 889
  • 7
  • 26
2
votes
4 answers

8-digit BCD check

I've a 8-digit BCD number and need to check it out to see if it is a valid BCD number. How can I programmatically (C/C++) make this? Ex: 0x12345678 is valid, but 0x00f00abc isn't. Thanks in advance!
1 2
3
12 13