[SOLVED] PIC CCS C Compiler Hexadecimal to Binary conversion

Status
Not open for further replies.

nagkiller

Full Member level 4
Joined
Jul 9, 2009
Messages
238
Helped
37
Reputation
74
Reaction score
37
Trophy points
1,308
Location
Brazil
Visit site
Activity points
2,706
PIC CCS C Compiler Hexadecimal to Binary Conversion : How to

Hello!!!

I need code in CCS Compiler to convert the value hex 4C48F5 into value 24 bit binary ( like this 101011110001001000110010 ).

Thanks for reply.

- - - Updated - - -

Solved!!!

In my case the code is:

Code:
void Convert(int Code1, int Code2, int Code3)
{
int aux;
int bit;
   for(aux = 0; aux < 8; aux++)
   {
      bit=(Code3>>aux)& 0x01;
   }
   for(aux = 0; aux < 8; aux++)
   {
      bit=(Code2>>aux)& 0x01;      
   }
   for(aux = 0; aux < 8; aux++)
   {
      bit=(Code1>>aux)& 0x01;      
   }
}

void main()
{
	Convert(0x4C,0x48,0xF5);
}
 

Re: PIC CCS C Compiler Hexadecimal to Binary Conversion : How to

Olá

me desculpe mas eu não entendi como obtenho o resultado de 4C48F5 = 101011110001001000110010
usando sua rotina acima.

eu preciso converter 0xAA (por exemplo) para: 10101010 (8 bits apenas)

Grato

- - - Updated - - -

Hello

I'm sorry but I do not understand how I get the result of 4C48F5 = 101011110001001000110010
using the above your routine.

I need to convert 0xAA (for example) for: 10101010 (8 bits only)
 

I agree, the original code looks suspicious. It does a shift then checks the LSB but overwrites it as it moves through each byte. It goes through the motions of converting to a single bit doesn't produce a result. Each time it goes through the 'for' loops it should store 'bit' somewhere. How it achieves that will depend on the desired format of the output, for example is it ASCII representations of the bits or is each bit returned as a different variable or in an array.

Brian.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…