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
21
votes
4 answers

Z80 DAA instruction

Apologies for this seemingly minor question, but I can't seem to find the answer anywhere - I'm just coming up to implementing the DAA instruction in my Z80 emulator, and I noticed in the Zilog manual that it is for the purposes of adjusting the…
PhilPotter1987
  • 1,306
  • 2
  • 12
  • 20
12
votes
10 answers

Assembler : why BCD exists?

I know BCD is like more intuitive datatype if you don't know binary. But I don't know why to use this encoding, its like don't makes a lot of sense since its waste representation in 4bits (when representation is bigger than 9). Also I think x86 only…
llazzaro
  • 3,970
  • 4
  • 33
  • 47
12
votes
3 answers

Python, how to decode Binary coded decimal (BCD)

Description of the binary field is: Caller number, expressed with compressed BCD code, and the surplus bits are filled with “0xF” I have tried to print with struct format '16c' and I get: ('3', '\x00', '\x02', '\x05', '\x15', '\x13', 'G', 'O',…
Whit3H0rse
  • 569
  • 2
  • 8
  • 16
11
votes
3 answers

How to convert BCD to decimal?

How can I convert a binary-coded decimal number into a decimal number in terms of representation ? I don't want to convert the value of it but rather the representation of it, here is what I mean. I want to convert 0x11 to decimal 11 (not 17) and…
Ammar
  • 1,203
  • 5
  • 27
  • 64
9
votes
5 answers

Binary coded decimal (BCD) to Hexadecimal conversion

can someone explain to me how to convert BCD to Hexadecimal? For example how can i convert 98(BCD) to Hexadecimal. Thanks.
iPadDevloperJr
  • 992
  • 3
  • 20
  • 34
9
votes
2 answers

Packing BCD to DPD: How to improve this amd64 assembly routine?

I'm writing a routine to convert between BCD (4 bits per decimal digit) and Densely Packed Decimal (DPD) (10 bits per 3 decimal digits). DPD is further documented (with the suggestion for software to use lookup-tables) on Mike Cowlishaw's web…
fuz
  • 88,405
  • 25
  • 200
  • 352
8
votes
2 answers

BCD math library for arbitrary big numbers?

I'm looking for a replacement of the stock Delphi Data.FmtBcd library because I just hit its limits like maximum decimal digits it can represent and program terminates with EBcdOverflowException. For the curious, I'm calculating arithmetic series…
David Unric
  • 7,421
  • 1
  • 37
  • 65
7
votes
2 answers

How do ASCII Adjust and Decimal Adjust instructions work?

I've been struggling with understanding the ASCII adjust instructions from x86 assembly language. I see all over the internet information telling me different things, but I guess it's just the same thing explained in a different form that I still…
emilxp
  • 91
  • 1
  • 1
  • 3
7
votes
10 answers

Unsigned Integer to BCD conversion?

I know you can use this table to convert decimal to BCD: 0 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 Is there a equation for this conversion or you have to just use the table? Im trying to write some…
Bramble
  • 1,395
  • 13
  • 39
  • 55
6
votes
2 answers

Decode binary coded decimal (BCD) to unsigned integer

The value used in my project is expressed with 4-bits binary coded decimals (BCD), which was originally stored in a character buffer (for example, pointed by a pointer const unsigned char *). I want to convert the input BCD char stream to an…
Golden Lee
  • 95
  • 1
  • 1
  • 4
6
votes
2 answers

Make an binary addition behave like a (packed-) decimal addition

I'm currently working on a restrictive environment where the only types allowed are : byte, byte[], short, short[]. I am almost certain that I can't import external libraries, since I'm working on a JavaCard, and have already tried such things,…
Harnex
  • 61
  • 3
6
votes
2 answers

BCD Adder in Verilog

I am trying to write a BCD Adder in Verilog, but I am having trouble with one of the modules. Specifically, the adder that takes two BCD digits and adds them. So, the idea is if the sum of the two digits is less than or equal to nine, then it is…
DemonicImpact
  • 307
  • 2
  • 6
  • 12
6
votes
10 answers

Convert integer from (pure) binary to BCD

I'm to stupid right now to solve this problem... I get a BCD number (every digit is an own 4Bit representation) For example, what I want: Input: 202 (hex) == 514 (dec) Output: BCD 0x415 Input: 0x202 Bit-representation: 0010 0000 0010 = 514 What…
Sagi
  • 783
  • 1
  • 8
  • 17
5
votes
5 answers

Convert really big number from binary to decimal and print it

I know how to convert binary to decimal. I know at least 2 methods: table and power ;-) I want to convert binary to decimal and print this decimal. Moreover, I'm not interested in this `decimal'; I want just to print it. But, as I wrote above, I…
AlannY
5
votes
0 answers

Converting an Int to a BCD byte array

I want to convert an int to a byte[4] array using BCD. The int in question will come from an device id and his needed to speak to an device via serialport. Is there any pre-made function that does this or can you give me a simple way of doing…
Kingpin
  • 1,067
  • 2
  • 14
  • 34
1
2 3
12 13