Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Binary to ASCII

Status
Not open for further replies.
I have some if needed in a pinch, but there is all kinds of Math routines on Piclist site.
.
Max.
 
sir if in bin i gave 07 then at corresponding asscii location i want the the ASCII character of 07 .i.e suppose I gave 50 in bin memory location then P should get display to particular ASCII location
 
Your not describing what you need so we can understand it.

i.e suppose I gave 50 in bin memory location then P should get display to particular ASCII location

makes NO sense.

ASCII location? 50 is not a binary number. Binary has only 2 digits 0 and 1.

You might want the stored number 50 (32+16+2) 0011 0010 or 32h to print as 50. Printing 32h is much easier.

Something easy is making 50 print as Hex 32h is much easier..

that requires some bit shifting and masking, but the root is making 0-16 print as 0-F.

The trick there is ASCII 48d is a '0'
and ASCII 65d is a capital "A".

So to print an internal number 0-9, you print the character 48+n; where n=0 through 9. Thus ASCII 48 is a '0'

When the number is between 10 and 15, you print the character 65 +n; where n=10 through 15.

A carriage return is 13 an a line feed is 10.

printing values of registers/memory locations in decimal is a typical programming assignment for beginners.

Now I could make the assignment harder by saying it's a signed number from -127 to 128, use leading zero supression. A positive number is represented by a leading space and negative number a "-" sign.
 
ASCII location? 50 is not a binary number. Binary has only 2 digits 0 and 1.

I think he was using hex representation.
0x50 represents P in ascii.

ascii01.png
 
It would be convenient the OP being sincere and tell how many things he ignores.

Given any number he should show he is capable to show it expressed: in decimal, in binary, in BCD packed, in BCD unpacked, in hex, and finally in ASCII. I am sure he is lost somewhere in between. That is why he asking for code.

Even Microchip has ANs working all maths with numbers in BCD. Enough to confuse even more the off guard newbie, but very practical sometimes.
 
To get the digits in decimal, You can divide the 8 Bit by 10.
The rest will give You the ones.
Store that.

Then divide the rest of the 8 Bit again by 10.
The Rest will give You the tens.
Store that in another location.

The Rest now into the 8 Bit will give You the hundrets.

When want to get ASCII Code for the Numbers add 30h to any Value - That's all.

That only works with positive values!

Another way to do that is to set a loop counter subtract first 100 and stop before the result is negative.
The loop Counter will give You the hundrets value.
From the Rest subtract 10 ( loop counter again ) and stop before the result is negative.
The rest are the ones then.

Witch method run's faster depends from the used chip.
 
I think he was using hex representation.
0x50 represents P in ascii.

ascii01.png

Yeah, sometimes the 'requests' are like projective tests, but I was thinking along the same lines - thought the OP was after something like this:

screenA1.jpg


It is past 'Monday', so we may be left to wonder for eternity.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top