| View previous topic :: View next topic | 
	
	
		| Author | Message | 
	
		| ljbeng 
 
 
 Joined: 10 Feb 2004
 Posts: 205
 
 
 
			    
 
 | 
			
				| Should be simple, convert 4 bytes to float32 |  
				|  Posted: Tue Nov 03, 2009 5:23 pm |   |  
				| 
 |  
				| With the pcwhd 4.096 and PIC24F, my float32 should be IEEE format, 4 bytes, correct?  I have the 4 hex bytes in an eeprom and I need to convert the bytes to float.  What is the command for this?  Thanks. |  | 
	
		|  | 
	
		| FvM 
 
 
 Joined: 27 Aug 2008
 Posts: 2337
 Location: Germany
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Tue Nov 03, 2009 5:29 pm |   |  
				| 
 |  
				| It's no actual conversion, just a copy. You can use make32() built in function to combine the bytes. If I remember right, PCD is using IEEE float with reversed byte order. |  | 
	
		|  | 
	
		| ljbeng 
 
 
 Joined: 10 Feb 2004
 Posts: 205
 
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Nov 04, 2009 8:46 am |   |  
				| 
 |  
				| Ok, I get it.... 
 
  	  | Code: |  	  | 
 float readfile(int16 srval){
 float rtval;
 pathval[0] = read_ext_eeprom(srval);
 pathval[1] = read_ext_eeprom(srval + 1);
 pathval[2] = read_ext_eeprom(srval + 2);
 pathval[3] = read_ext_eeprom(srval + 3);
 pathv = make32(pathval[3],pathval[2],pathval[1],pathval[0]);
 memcpy(&rtval,&pathv,4);
 return rtval;
 }
 
 | 
 |  | 
	
		|  | 
	
		| FvM 
 
 
 Joined: 27 Aug 2008
 Posts: 2337
 Location: Germany
 
 
			    
 
 | 
			
				|  |  
				|  Posted: Wed Nov 04, 2009 9:34 am |   |  
				| 
 |  
				| Yes, basically correct, but: 
  	  | Code: |  	  | float readfile(int16 srval){ union {
 float rtval;
 int8 pathval[4];
 }u;
 u.pathval[0] = read_ext_eeprom(srval);
 u.pathval[1] = read_ext_eeprom(srval + 1);
 u.pathval[2] = read_ext_eeprom(srval + 2);
 u.pathval[3] = read_ext_eeprom(srval + 3);
 // Two copy actions can be saved
 //pathv = make32(pathval[3],pathval[2],pathval[1],pathval[0]);
 //memcpy(&rtval,&pathv,4);
 return u.rtval;
 }
 | 
 |  | 
	
		|  | 
	
		|  |