#decode from binary to bcd to 2 display?
181 messages · Page 1 of 1 (latest)
yes.
I don't know exactly how to do it because I tried to decompose each number by adding, but of course that is too many conventions for a small size.
how would you convert binary to decimal in real life?
Counting
A smarter way
Something more efficient
Simply counting up to N in both bases is far too slow
Instead of counting with addition and subtraction, try multiplication and division
And how am I going to represent that multiplication and division in 2 display?
In the displays? No you convert it before displaying
what exactly do you want to do?
I am making a calculator whose inputs are A and B and they are BCD
What is BCD?
An encoding where the highest number is 9
Oh, why do you need that?
simplicity to show the selected number on a display with some switches before multiplying them
Right, and what type of display do you have in this case?
a 7 segment,i used a convert from bcd to 7 segment
You can easily convert a normal binary number into a decimal one, you know?
define decimal
You don't know what a decimal number is?
like 10,9 right?
The decimal numeral system (also called the base-ten positional numeral system and denary or decanary) is the standard system for denoting integer and non-integer numbers. It is the extension to non-integer numbers (decimal fractions) of the Hindu–Arabic numeral system. The way of denoting numbers in the decimal system is often referred to as d...
hmm let me do some tests
but how i can i show in the display a 9 when its 100000000? with xnor?
????
in decimal 9 its 1 with 8 zero rigth?
Have you played Turing Complete?
yes
How much computer science do you knw?
why are you already making a calculator?
curiosity
9 in binary 1001
What exactly is the goal here? BCD to 7 segment display is easy
Many calculators work by storing the numbers internally in BCD and doing arithmetic on BCD numbers
Additional conversion is not required
FWIW, some (older) ISAs even have instructions that help with BCD math. Like the Gameboy CPU based on (but not equivalent to) z80 has a DAA instruction, m68k has ABCD, SBCD, NBCD and 68020 and up have PACK, UNPK
BCD math can in some isolated instances be more efficient on those older architectures where every cycle may count, for instance for score-keeping, where you need to display each digit of a score 25, 30, 50 or 60 times per second and dividing is costly on that architecture. In BCD you have a simple direct correspondence between stored nibble or byte and displayed digit.
x86 has them too lol
Double dabble
but in decimal its 10^8 rigth?
No, 10 in decimal is 10
I have not yet found a design exclusively for BCD only binary
decimal is base 10
And what's the point with what the other guy says because I don't understand it?
They were explaining that it's base ten and not a number with a decimal point. (which it also is, but not relevant for this context)
aah I only put the comma to put 10,9,8... etc just numbers
Here's algorithms for packed BCD https://homepage.divms.uiowa.edu/~jones/bcd/bcd.html#packed
fair enough, I'm not an x86 guy at heart 🫣 But yeah, figures, the x86 architecture goes far back in time
the original 8086 had them* and now we're stuck with them
*presumably because it was being marketed at calculators initially, though that changed
it seems like you might not understand how numbers work?
123 means 1 * (5 + 5)^2 + 2 * (5 + 5)^1 + 3 (*index error)
for binary numbers you need to use 1+1 instead of 5+5
1 * (5 + 5)^2 + 2 * (5 + 5)^1 + 3 = 2^6 + 2^5 + 2^4 + 2^3 + 2^1 + 1 (notice 2^2 was skipped, but it's mostly a coincidence that almost all the rest were here)
changing between them is best done by multiplication and division NOT addition and subtraction
to convert 123 into binary: just keep dividing by 2
123/2 = 61 remainder 1;
61/2 = 30 remainder 1;
30/2 = 15;
15/2 = 7 remainder 1;
7/2 = 3 remainder 1;
3/2 = 1 remainder 1;
1/2 = 0 remainder 1
then just read off all the remainders backwards
1 1 1 1 0 1 1 (no remainder = remainder 0)
to convert into decimal just keep dividing by (try to guess) ||the thing you get when you do 5+5|| and read off all the remainders backwards
if your goal is to take a binary number and put it on a 7-segment display in decimal then you need to turn the binary number into a decimal number and then just pick the right lights for each digit
The irony of being so rudely sarcastic and then doing the math incorrectly 🙃
Please remember and take to heart rule 1 of the server.
Bluntness is fine, disagreements are fine, but strictly with respect
This is blatantly disrespectful, both in tone/content, and also because it seems you didn't do the due diligence of reading the thread back enough to understand the question you were answering before responding like that.
but after reading comments like this
i think this was it, then?
but for BCD calculation really you have to grind it out by hand and endure the struggle
implement everything the game told you to do with binary except do it in decimal this time
That's not exactly a particularly helpful solution since they don't know how in the first place.
for addition it's not too awful but multiplication is rough
the first possible solution for BCD addition, to start, is just binary addition and then fix the answer if it's out of bounds (more than 9)
He was confused because "decimal" is an overloaded word - the much more common usage is to refer to fractional numbers written with a radix point ("decimal point" in base 10) and that's a perfectly understandable confusion. Your answer to the question was unrelated.
For BCD addition, you may notice the question is already well-answered in the thread.
For example here, and the next comment which also includes information about packed BCD. Repeating the same algorithms isn't helpful, though fresh contributions (e.g. multiplication?) may be welcomed by OP
When the first image you see is this one, what do you think I'm going to think?
@peak tendon As I said for me, I need to have an acceptable size
Of course I could make my own converter with Karnaugh maps but it would be impractical at a practical size....
This its perfect, Thanks
but i still need one with cascade output,because its maximum output will always be 19 and I need 81
I have only found this but it is discontinued and does not have an internal diagram to recreate it just for operation
Yes, the carry output can cascade into the carry input of the next one just fine
That's the whole point of the carries!
I mean to have an output greater than 19
Then I don't understand, since that single circuit only has outputs up to 18 (9+9)
BCD adders work like regular adders; if you want more digits~bits, you connect them by rippling the carries and it works
The carry-in to a BCD adder goes into the top 4-bit adder in that diagram, idk why they didn't include that
Do you want me to build it and send a screenshot? Might be clearer
but I need a multiplier (9*9=81)
so I don't think it will help me just to add the carry I would need to differentiate when the decimal is greater than 1
To put 2,3...etc
ok i'll build it, hang on
there's the circuit from the diagram
8888 + 1022 = 9910
@woven edge
if you also want to do multiplication with your bcd digits (e.g. because you want your calculator to do multiplication) then you can do it the same way you'd do it on paper - compute partial products and add them with BCD adders. Or you could convert to binary, use a binary multiplier, and convert back, but that's even harder I think.
but you don't need to do multiplication in order to implement addition
to reiterate, the suggestion here is to never use binary at all
keep all of your calculator's numbers in BCD, all the time
Oh let me try this,thanks
I will built this
Wait because I don't know if you're making me understand, would there be any way to differentiate between units and tens to be able to use two BCD to 7 segment converters?
the difference between units and tens doesn't matter
I have four byte wires up there at the output, in order from left to right they have the values 9, 9, 1, 0
to convert those values to 7seg displays, you don't have to know or care which one represents which power of 10
you just have 4 7seg displays and put each digit on one of them
hhm I think I understand it, I'm going to simulate it in Proteus
I have already adapted it to my problem
now I can use another multiplier design that uses binary or use a sequential adder
Thanks @mellow lily
Although I will have to still investigating because I still have the same problem because if it has a number greater than 19 it does not separate the number
What's the top input, that looks like a backwards c?
I'm not sure what I'm looking at here but 19 in BCD should be encoded as [0b0001][0b1001] (whether those two nybbles are packed into a byte or carried around separately is irrelevant)
feeding that to two separate 7 segment decoder+displays will display a 1 and a 9
What happens is you gave me an adder but from bytes to bcd and I tried to adapt it to bits
no, that adder was for BCD
this is adding two 4-digit BCD numbers and getting a 4-digit BCD result
I'm using byte wires but you can see that the adder is completely ignoring the top 4 bits
so each "byte" wire is really just carrying a single 4-bit BCD digit
no "adapt"ing was needed
what is the value in the top left of your image supposed to be?
Squinting at the switches it looks like 11
which is not a valid BCD value
BCD can only represent the values 0-9
binary values 0b1010, 0b1011, 0b1100, 0b1101, 0b1110, and 0b1111 are all invalid
It's my fault I didn't see the output carry and I thought I was doing it wrong but no.
so this output is correct then
yes,Now I just have to investigate to be able to create a sequential multiplier.
You could do a matrix / ROM based multiplication for 4 bits BCD multiplier times 4 bits BCD multiplicand -> 2 x 4 bits digit product. The multiplier could address the row and the multiplicand the column (or vice versa).
It's super wasteful regarding space / number of gates, but also "instant" and simple to understand.
you can ignore the difference between rows and columns and just use a program component for the table
(actually you probably have to use a ROM because you can't put programs in customs for some reason, but you can flash the ROM once and then treat it like a program)
Right now I am doing sequential multiplication
i don´t like to use ROMs
why not? lookup tables are realistic
would lose grace for me
I am making a sequential multiplier and what I am going to do is compare A and B and depending on which is smaller, I add the larger B or A times
hardware isn't graceful 🙃
all sorts of "hacks" and tricks to improve performance that are not elegant
that is not a good algorithm
you should use the "sequential" aspect to compute one partial product per cycle and keep a running total
this limits the number of cycles you take to the number of digits in the numbers
(or a constant factor, if it takes more than one clock to compute each partial product)
but repeated addition can take much, much, much, much, much longer - completely unacceptable for a calculator
like my multiplier is not going to be result+A or B, the speed is not going to affect me so much.
I don't understand the image
my point is that a multiplication like 999x999 should take ~3 iterations
not 999 iterations
it takes 2 interactions for 3*7, if the result of the first sum is greater than 6 add 6 otherwise leave the number and then the result+initial number again
I don't know if you could show me how to decompose the numbers.
So you add the numbers in parallel?
i'd do it by computing one partial product per cycle
use the least significant digit of the multiplier and the entire multiplicand
compute the product of just those
add it to the running total
then shift the multiplier right one digit and the multiplicand left one digit
and repeat
hmm let me design it mathematically
for the record this algorithm is quite a bit easier in binary
if you want to invest in the binary <-> bcd conversions just for multiplications, that might be worth it
idk what real old calculators did
I have not found information about multiplications with bcd, only additions with bcd
one digit by N digit multiplication seems feasible
multiply the one digit by each of the N digits, which gives you a bunch of 2-digit results, and then combine the results with an N digit bcd adder
so the whole multiplier should be two N-digit BCD adders and two bcd shift registers (one for the multier and one for the multiplicand)
plus some small amount of control logic I guess
Im late to the party but I made a binary to 7-seg converter before
It uses the shift add-3/double-dabble algo, heres the 8bit one
add-3
Some easy way to do the conversion is, simply store the LUT into a program component
BCD to display is essentially LUT
LUT = Look Up Table
if the LUT is not that complicated, just hardcode it in whatever means you prefer
but for Binary to BCD, that require some work, but for 2 digits it's still easy to store the conversion LUT in a program component