Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Need to convert a string of binary numbers to a decimal value.

Status
Not open for further replies.

jdraughn

Junior Member level 1
Joined
Jul 29, 2009
Messages
19
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,621
I have finally got to the point where I can read the SIRC sequence from a Sony remote using a a IR receiver. The remote I have outputs 12 bits, first, the 7 bits giving the command (power, play, volume up, ect...), and the last 5 bits are the device ID (VCR, DVD, TV, etc..).

So as I receive these values I save a '1' or a '0' in a string, but they are backwards.

For instance, pressing the play button sends (0,1,0,1,1,0,0,1,1,1,0,0).
So it sent the command ID as 0101100, and the device id as 11100.

But the command id's value is actually reversed, 0011010 = 26
the device id is actually 00111 = 7.

So I need to either not build these up in a string and instead calculate these values in reverse as they are coming in, or build up the value in a reverse loop, once for the command and once for the device.

Does anyone have any helpful information? I am not very good with binary arithmetic.
 

Set a variable for command ID and initialize it to zero.
Initialize a counter to 7
As a bit comes in, if it is zero, clear bit (indicated by counter) of the commandID variable, otherwise set this bit.
Decrement counter and repeat till counter becomes zero.
So in first loop you will set / clear 7th bit of your variable, in 2nd loop, the 6th bit and so on.

Another way is to use Rotate instruction. Set / clear the carry flag depending on the bit you received and then rotate your variable through the carry flag.

In the end, your variable will have the command ID as a hex value. You can then convert it to ASCII.
 

You can write the string in revere while you receive it, i assume you know the length of the string so instead of writing to the char array from 0 to 11 you can write from 11 to 0.
You can also create a function the read the character in reverse and return the string as you want it.

Alex
 

Thanks, I was able to get it working.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top