7 digit dicimal number into a 21-bit binary number

6 posts / 0 new
Author
Message

Hello everybody,

I program in c with ATmel studio 7,

work with the protocol POCSAG and would like to do the following:

Conversion of a seven-digit decimal number into a 21-bit binary number.

The code I have is limited.

Can anyone help me with a code that works?

greeting
Etie

Do you understand the basic concept of Place Value - used when writing numbers?

http://www.bbc.co.uk/bitesize/ks...

It's simply a matter of multiplying each digit by its place value, and summing ...

But note that 9999999 won't fit into 21 bits ...

Thank you for responding promptly.
I would like to know this fact:
If I send the following 7 decimals
0000000 must i have as banary 0000000 0000000 0000000

You do understand that leading zeros make no difference whatsoever to the value of the number?

In C normally you would use atoi() for this (ASCII TO Int) but in AVR the int type is just 16 bit and can only hold +32767..-32768 so for AVR you would use the "long" version of the same routine which is atol() (fourth character is L for lima).

```char input[] = "1234567";
int32_t num;

num = atol(input); // now num contains 1234567```

signed long int or more usefully int32_t on AVR has a numeric range of +2,147,483,647 .. -2,147,483,648 so can accommodate a little over 9 decimal digits.