INT to Byte conversion for decimals

For general Flowcode discussion that does not belong in the other sections.
Post Reply
walbeek
Posts: 28
http://meble-kuchenne.info.pl
Joined: Thu Dec 17, 2020 3:25 pm
Location: Netherlands
Been thanked: 2 times

INT to Byte conversion for decimals

Post by walbeek »

Hi there,

I have used a INT variable in a counter program.
The INT can be filled with a value from 001 to 999.
I would like to split the value to 3 bytes.
So, the first (right) character should be converted to Byte_Low
The center character to Byte_Middle
The left character to Byte_High.
For example, the value of the int is 432.
After conversion, Byte_Low = 2, Byte_Middle = 3, Byte_High = 4.

The bytes have to be written to a 7-segment display and Eeprom.
Please let me know if this is possible.

Thanks,
Rinie
Best regards,

Rinie

kersing
Valued Contributor
Posts: 193
Joined: Wed Dec 02, 2020 7:28 pm
Has thanked: 79 times
Been thanked: 64 times

Re: INT to Byte conversion for decimals

Post by kersing »

Hi Rinie,

Yes this is possible.

Just divide the INT by 100 for byte_high, then take the remainder of the division by 100 and divide it by 10, that is middle and low is the remainder of a division by 10. High, middle and low should be bytes or ints, no floating point variables for this to work.

So:
High = Int / 100
Middle = ( Int % 100 ) / 10
Low = Int % 10

artan
Posts: 13
Joined: Mon Oct 11, 2021 5:27 pm

Re: INT to Byte

Post by artan »

Hello, can you help me that an int number for example -5 or -35 which I present in the lcd I can write on the eprom and read later, I am using an internal eprom atmega8. thank you

chipfryer27
Valued Contributor
Posts: 1684
Joined: Thu Dec 03, 2020 10:57 am
Has thanked: 374 times
Been thanked: 583 times

Re: INT to Byte conversion for decimals

Post by chipfryer27 »

Hi

As your post isn't really to do with the original post, you should have started a new topic.

You can use the EEPROM [2D[ component found under Storage. Integers require two bytes of storage on an 8-bit device so you will need two bytes per integer stored.

Do note that EEPROM locations have limited erase/write capabilities, 100,000 times for your chip, so it's better to only update the EEPROM value if it has changed.

A search of the forum should show some techniques on using locations, such as monitoring the erase/write cycles and moving location if approaching 100,000 cycles etc.

Regards

walbeek
Posts: 28
Joined: Thu Dec 17, 2020 3:25 pm
Location: Netherlands
Been thanked: 2 times

Re: INT to Byte conversion for decimals

Post by walbeek »

@ kersing,

Thanks for your help, works very well.
I have also managed to get it working the other way around.
So reading from the EEPROM and convert the 3 BYTES into a INT variable.
Thanks again!

Rinie
Best regards,

Rinie

Post Reply