CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How to I convert a 16 bit number to two 8 bit?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Michael Sheedy
Guest







How to I convert a 16 bit number to two 8 bit?
PostPosted: Mon Nov 05, 2001 7:09 pm     Reply with quote

I am using a 16F872 10 bit ADC. I am storing the 10 bit number into a 16 bit register. How do I break the 16 bit number into 2 8 bit numbers so I can individually manipulate each byte?

Thanks in advance

Michael
___________________________
This message was ported from CCS's old forum
Original Post ID: 958
Justin Dobbs
Guest







Re: How to I convert a 16 bit number to two 8 bit?
PostPosted: Mon Nov 05, 2001 9:46 pm     Reply with quote

Michael,

int16 big_number;
int8 high_byte;
int8 low_byte;

big_number=get_reading();
low_byte=big_number & 0xff;
high_byte=big_number>>8;

not sure if this is more efficient or not:

big_number=get_reading();
low_byte=big_number&0xff;
big_number>>=8;
high_byte=big_number;

Justin Dobbs

:=I am using a 16F872 10 bit ADC. I am storing the 10 bit number into a 16 bit register. How do I break the 16 bit number into 2 8 bit numbers so I can individually manipulate each byte?
___________________________
This message was ported from CCS's old forum
Original Post ID: 963
Tomi
Guest







Re: How to I convert a 16 bit number to two 8 bit?
PostPosted: Tue Nov 06, 2001 3:01 am     Reply with quote

Without arithmetics you can use the #byte directive:

int16 value;
#byte valueL = value
#byte valueH = value+1

Usage (example):
putchar(valueL); // send over RS232
putchar(valueH);

:=I am using a 16F872 10 bit ADC. I am storing the 10 bit number into a 16 bit register. How do I break the 16 bit number into 2 8 bit numbers so I can individually manipulate each byte?
:=
:=Thanks in advance
:=
:=Michael
___________________________
This message was ported from CCS's old forum
Original Post ID: 967
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group