Convert a string or int into a byte on a PIC WEB

Have you got the greatest 48 bit multiplier ever conceived? Prove it - post your code here.

Moderator: phalanx

Post Reply
JFE
Posts: 10
Joined: Wed Sep 07, 2011 11:00 am

Convert a string or int into a byte on a PIC WEB

Post by JFE » Fri Sep 16, 2011 5:45 am

Hello, I need help for converting a string or int into a byte, and backwards. For example: the string=125 or int=125 into a byte=01111101.
Thanks.

FLOWMEET
Posts: 8
Joined: Fri Dec 03, 2010 5:55 am

Re: Convert a string or int into a byte on a PIC WEB

Post by FLOWMEET » Wed Nov 28, 2012 11:25 am

n (integer decimal number) = bm * 2^m + bm-1 * 2^m-1 + .... b3 *2 ^3 + b2 * 2^2 + b1 * 2^1 + b0

b0 = n%2
b1 = (n/2)%2
b2 = (n/4)%2
b3 = (n/8)%2
...
...
until n/2^x = 0

------
sscanf(string",%d", &a_number)

Best regards.
http://www.flowmeet.com

Post Reply