View previous topic :: View next topic |
Author |
Message |
hemnath
Joined: 03 Oct 2012 Posts: 242 Location: chennai
|
larger values on LED display |
Posted: Mon Aug 20, 2018 3:43 am |
|
|
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: 9269 Location: Greensville,Ontario
|
|
Posted: Mon Aug 20, 2018 7:28 am |
|
|
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: 19588
|
|
Posted: Mon Aug 20, 2018 8:36 am |
|
|
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.... |
|
|
|