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 support@ccsinfo.com

larger values on LED display

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



Joined: 03 Oct 2012
Posts: 227
Location: chennai

View user's profile Send private message

larger values on LED display
PostPosted: Mon Aug 20, 2018 3:43 am     Reply with quote

Hi,

I have Four digit Seven segment LED display and my maximum decimal value is 32767. I thought to convert it to hex, so that the value can be displayed on the four digit seven segment display. Eg: 32767 in a Four Digit Seven Segment display.

32767 in decimal(5 digits) = 7FFF in hex(4 digits)

To display 4 digits on LED display, For decimal numbers I used this routine earlier,
digits[0] = (disp_value/1000)%10;
digits[1] = (disp_value/100)%10;
digits[2] = (disp_value/10)%10;
digits[3] = (disp_value%10);

How to do it for hex? kindly help me.
temtronic



Joined: 01 Jul 2010
Posts: 9081
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Aug 20, 2018 7:28 am     Reply with quote

quick answer...
use google ' convert decimal to hex ', lots of 'hits'.

I don't have code, or time to cut code though it is simple to do.
Perhaps someone else can walk you through it.
It's only 4 steps, 2 operations for each 'digit'.
Ttelmah



Joined: 11 Mar 2010
Posts: 19195

View user's profile Send private message

PostPosted: Mon Aug 20, 2018 8:36 am     Reply with quote

Don't get me wrong, but you don't actually need to do any conversion. The low 4bits of disp_val is digits[3] (disp_value & 0xF). The next nibble is digits[2] ((disp_value>>4)&0xF). The next nibble is digits[1] ((disp_value>>8)&0xF), while the last nibble is digits[0] ((disp_value>>12)&0xF).
There are 'trick' ways (in particular using swap), that can do this slightly more efficiently, but this is so much more efficient than %10 already that it probably isn't worth getting involved in these....
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