Discussion in "Software" started by    redsuns    Apr 11, 2010.
Sun Apr 11 2010, 10:59 am
#1
hello, i now have 3 bytes that need to place as first byte,second byte and third byte in a variable then converted into a decimal number ,
but the result is 0, can anyone help
supposely the b1,b2 and b3 for me is variable

#include <stdlib.h>

unsigned char fb,sb;
unsigned int count,size;
unsigned long packages,temp,b1,b2,b3;
float temppack;
char pac_show [sizeof(unsigned long)*8+1];

void main(void)
{
	b1 = 0xF5;
	b2 = 0xCE;
	b3 = 0x12;
	temp=b1;
	temp<<8;
	temp+=b2;
	temp<<8;
	temp+=b3;
	temppack=temp/506;
	packages = (unsigned long) temppack;
	ultoa(packages,pac_show,10);
	LCD_sendstring(pac_show);
}


[ Edited Sun Apr 11 2010, 11:25 am ]
Sun Apr 11 2010, 05:12 pm
#2
problem is there, make the following changes..

temp=b1;
temp=temp<<8;
temp=temp+=b2;
temp=temp<<8;
temp=temp+=b3;


you forgot to store temp after shifting

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Tumergix
Sun Apr 28 2024, 12:59 am
StevenDrulk
Sat Apr 27 2024, 08:47 pm
StephenHauct
Sat Apr 27 2024, 09:38 am
Adamsaf
Sat Apr 27 2024, 07:12 am
Robertphype
Sat Apr 27 2024, 12:23 am
ktaletrryp
Fri Apr 26 2024, 10:55 pm
Robertrip
Fri Apr 26 2024, 11:20 am
ArnoldDiant
Fri Apr 26 2024, 03:53 am