DEC to BIN

For questions and comments on programming in general. And for any items that don't fit into the forums below.

Moderators: Benj, Mods

Post Reply
User avatar
badir79
Posts: 12
Joined: Mon Oct 29, 2012 10:44 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

DEC to BIN

Post by badir79 »

Hi Everyone!!! I guess this topic already exist, but I just can´t find it in my quick search...

Well, I need some help. How i can convert decimal numbers into binary numbers and show them on a display? In other words, how i can decompose a single byte into their bits and manipulate them?

Thanks a lot for helping me!!! :D

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: DEC to BIN

Post by Enamul »

Hi,
You can try the following code...
Attachments
DEC_BIN.fcf
(11.5 KiB) Downloaded 376 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
badir79
Posts: 12
Joined: Mon Oct 29, 2012 10:44 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: DEC to BIN

Post by badir79 »

Enamul, thank you very much for your help... But I can´t open it because this file was made in Flowcode V5 I guess, and I only have Flowcode V4; please, can you give it to me in V4, or post an image of the flowchart to see what can I do... Thanks!!!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: DEC to BIN

Post by Enamul »

Here it is...
Attachments
binm.png
(102.1 KiB) Downloaded 1842 times
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
badir79
Posts: 12
Joined: Mon Oct 29, 2012 10:44 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: DEC to BIN

Post by badir79 »

Enamul, this is just what I was looking for... Thank you very much!!!

User avatar
badir79
Posts: 12
Joined: Mon Oct 29, 2012 10:44 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: DEC to BIN

Post by badir79 »

Hi,
Now I need to convert single bits from one port pin into a byte... How can I do that? how can I do this inverse process?

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: DEC to BIN

Post by Enamul »

This one is not so simple like earlier one..what will be the bit rate in that port..Will you allowed to interrupt to detect 1. Is that a continuous transmission or single byte transmission? I have made a program for you but need to tune depending on these Q/A.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
badir79
Posts: 12
Joined: Mon Oct 29, 2012 10:44 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: DEC to BIN

Post by badir79 »

Thank you Enamul, let me see... this is for a serial comunication at a baud rate of 10400 bps, so, the time bit is about 96 micro-seconds. I was thinking in an interrupt, but I need to evaluate that, because in this proyect there will be just one bidireccional comm line, so I will have one pin for TX and one for RX, but due to the interface design, every time I send a bit by the TX port, it reflects in the RX port, so, I'm not sure at this moment an interrupt would work properly for this case. Another thing to consider is that it will need to detect start bit and stop bit. Start bit= '0',/ Byte bits,/ Stop bit ='1'.
Thanks alot for your help Enamul, if you need another detail please ask me... Thanks!!!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: DEC to BIN

Post by Enamul »

Ok..In that case you can simply use RS232 and that's most easy to deal with. If you don't have hardware RS232 in PIC still you can use software RS232.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
badir79
Posts: 12
Joined: Mon Oct 29, 2012 10:44 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: DEC to BIN

Post by badir79 »

Thank you very much Enamul, I will try it with RS232 component...

User avatar
badir79
Posts: 12
Joined: Mon Oct 29, 2012 10:44 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: DEC to BIN

Post by badir79 »

Hello! This is another issue that I have at this moment... I have an hexadecimal value in a string, this is an address for a external EEPROM, from this value, I need to get the memory's high and low addresses , then I need to send these string values as individual bytes via i2c, but, I can't send it as string, so I use the function BYTE = StringToInt (STRING)

Example1:

String 0x47E
String_H = 04
BYTE1 = StringToInt (String_H)
BYTE1= 4

String_L = 7E
BYTE2 = StringToInt (String_L)
BYTE2 = 7

Bytes sent via i2c: 0107, but I need to send 017E

Example2:

String 0x190
String_H = 01
BYTE1 = StringToInt (String_H)
BYTE1= 1

String_L = 90
BYTE2 = StringToInt (String_L)
BYTE2 = 90

Bytes sent via i2c: 015A, but I need to send 0190

So, the addresses sent are not equals to the addresses that I need to send. How can I convert these bytes to hex numbers, or, how can I keep the same value of these strings?

Thanks a lot for helping me!!!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: DEC to BIN

Post by Enamul »

Hi,
First of all you can declare an INT variable for the address. In calculation box, just put your hex value in that variable and then simply you have to split that into low and high byte.
Address=0x47E
BYTE_L =Address AND 0x00FF
BYTE_H =Address >> 8
Hope this helps.
Enamul
University of Nottingham
enamul4mm@gmail.com

User avatar
badir79
Posts: 12
Joined: Mon Oct 29, 2012 10:44 pm
Has thanked: 3 times
Been thanked: 2 times
Contact:

Re: DEC to BIN

Post by badir79 »

Enamul, I tried that and it works great!!!

Thank you very much!!!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times
Contact:

Re: DEC to BIN

Post by Enamul »

Glad to know that it worked.
Enamul
University of Nottingham
enamul4mm@gmail.com

Post Reply