#decode from binary to bcd to 2 display?

181 messages · Page 1 of 1 (latest)

woven edge
#

It's possible?

gilded condor
#

yes.

woven edge
# gilded condor 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.

peak tendon
#

how would you convert binary to decimal in real life?

peak tendon
#

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

woven edge
peak tendon
#

In the displays? No you convert it before displaying

late topaz
woven edge
late topaz
#

What is BCD?

woven edge
late topaz
#

Oh, why do you need that?

woven edge
late topaz
#

Right, and what type of display do you have in this case?

woven edge
late topaz
#

You can easily convert a normal binary number into a decimal one, you know?

woven edge
#

define decimal

late topaz
#

You don't know what a decimal number is?

woven edge
#

like 10,9 right?

late topaz
#

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...

woven edge
#

hmm let me do some tests

#

but how i can i show in the display a 9 when its 100000000? with xnor?

late topaz
#

????

woven edge
#

in decimal 9 its 1 with 8 zero rigth?

late topaz
#

Have you played Turing Complete?

woven edge
#

yes

late topaz
#

How much computer science do you knw?

woven edge
#

in turing complete?

late topaz
#

why are you already making a calculator?

woven edge
gloomy crescent
#

9 in binary 1001

mellow lily
#

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

proven pecan
#

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.

mellow lily
#

x86 has them too lol

lilac citrus
#

Double dabble

woven edge
gloomy crescent
#

No, 10 in decimal is 10

woven edge
gloomy crescent
#

decimal is base 10

woven edge
gloomy crescent
#

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)

woven edge
#

aah I only put the comma to put 10,9,8... etc just numbers

mellow lily
proven pecan
mellow lily
#

the original 8086 had them* and now we're stuck with them

#

*presumably because it was being marketed at calculators initially, though that changed

peak tendon
#

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

mellow lily
#

Please remember and take to heart rule 1 of the server.

#

Bluntness is fine, disagreements are fine, but strictly with respect

mellow lily
peak tendon
#

fuck

#

yeah i realize

peak tendon
peak tendon
#

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

gloomy crescent
#

That's not exactly a particularly helpful solution since they don't know how in the first place.

peak tendon
#

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)

mellow lily
# peak tendon but after reading comments like this

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.

mellow lily
woven edge
#

@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....

woven edge
#

but i still need one with cascade output,because its maximum output will always be 19 and I need 81

woven edge
#

I have only found this but it is discontinued and does not have an internal diagram to recreate it just for operation

mellow lily
#

That's the whole point of the carries!

woven edge
#

I mean to have an output greater than 19

mellow lily
#

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

woven edge
#

To put 2,3...etc

mellow lily
#

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

woven edge
#

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?

mellow lily
#

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

woven edge
#

hhm I think I understand it, I'm going to simulate it in Proteus

woven edge
#

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

tropic notch
#

What's the top input, that looks like a backwards c?

mellow lily
#

feeding that to two separate 7 segment decoder+displays will display a 1 and a 9

woven edge
#

What happens is you gave me an adder but from bytes to bcd and I tried to adapt it to bits

mellow lily
#

no, that adder was for BCD

mellow lily
mellow lily
#

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?

tropic notch
#

Squinting at the switches it looks like 11

mellow lily
#

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

woven edge
#

It's my fault I didn't see the output carry and I thought I was doing it wrong but no.

mellow lily
#

so this output is correct then

woven edge
#

yes,Now I just have to investigate to be able to create a sequential multiplier.

proven pecan
#

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.

mellow lily
#

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)

woven edge
#

Right now I am doing sequential multiplication

mellow lily
#

why not? lookup tables are realistic

woven edge
#

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

mellow lily
#

all sorts of "hacks" and tricks to improve performance that are not elegant

mellow lily
#

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

woven edge
#

like my multiplier is not going to be result+A or B, the speed is not going to affect me so much.

mellow lily
#

I don't understand the image

#

my point is that a multiplication like 999x999 should take ~3 iterations

#

not 999 iterations

woven edge
#

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

woven edge
mellow lily
#

9x999 + 90x999 + 900x999

#

same way you did it in school

woven edge
#

So you add the numbers in parallel?

mellow lily
#

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

woven edge
#

hmm let me design it mathematically

mellow lily
#

if you want to invest in the binary <-> bcd conversions just for multiplications, that might be worth it

#

idk what real old calculators did

woven edge
#

I have not found information about multiplications with bcd, only additions with bcd

mellow lily
#

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

odd estuary
#

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

wooden spruce
#

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