decimal value starting with 0

I would like to store time in format HHMM/HMM in an array. To be more precise: 100*hours+minutes. Is it possible to store e.g. 00:10 as 010 or 0010 so it will be treated as decimal not octal?

struct Program{
  int weekDay; //day of week 0=Sun, 1=Mon, 2=Tue, ..., 6=Sat
  int timeStart; //when to start = hour + 100* minutes (8:10 = 810, 20:01 = 2001, 23:43 = 2342 etc.)
  int timeStop; //when to stop = hour + 100* minutes (8:10 = 810, 23:43 = 2342 etc.)
  int active; //how long Relay1 is active
  int pause; //how long pause lasts
  bool Speed;     //state of Relay 2 during whole cycle 1=HIGH, 0=LOW.
};
Program program[]={
  {1,   700,  800,  5, 15, 1},
  {1,   831, 2000,  5, 25, 0},
  {1,  2001, 2130,  5, 15, 1},

};

Sure, just specify it without the leading zeroes. Storage is a different matter, as it is in binary and has no inherent character representation.

If you're hung up on specification you could do it like this:

#define HOURS 100
...
Program program[]={
  {1,   7*HOURS+00,  0*HOURS+10,  5, 15, 1},

or something like that.

You're confusing storage with display.

I know I can store it as 10 (00:10). Or I can store hours and minutes separately and do the math later (100*hours+minutes) but is is possible to define numeral system of variable? Maybe during defining struct/variable?

The number/value is just that. A numerical value, whether it's in octal, binary, trinary, hex... doesn't matter. It's a number representation.

What does matter is when you want to retrieve or display that value.

what you could do is create an array with 4 bytes. The arduino saves this value in binary and doesn't know any difference until its time to display it somehwere.

maybe try:

byte time[4] = {0};

or you could use a struct:

struct TIME {
  byte h1;
  byte h0;
  byte m1;
  byte m0;
};

TIME timeValue = {0,4,2,7};
// h1 = 0 (timeValue.h1)
// h0 = 4 (timeValue.h0)
// m1 = 2 (timeValue.m1)
// m0 = 7 (timeValue.m0)
// Time is 04:27

is possible to define numeral system of variable? Maybe during defining struct/variable?

The Time library has ready made structs for that purpose.

If you mean printing the leading zeros, try:

if(hours < 10)
  Serial.print("0");
Serial.print(hours);
Serial.print(":");
if(minutes < 10)
  Serial.print("0");
Serial.println(minutes);

Thanks all for help.
I know that I can store 00:10 as {10} {0,10} {0,0,1,0} etc.
I know I can use Time library.
I know that I can add “0” for hours<10.
I just want to know if I can force arduino to read 0010 as 10?
I just thought that I can store it as char and convert it but maybe there is a simpler way like adding DEC or something similar?

If you store it as a string, atoi() doesn't care if there are leading zeros or not.

blh64:
If you store it as a string, atoi() doesn't care if there are leading zeros or not.

But only if it's ANSI compliant.

polanin:
Thanks all for help.
I know that I can store 00:10 as {10} {0,10} {0,0,1,0} etc.
I know I can use Time library.
I know that I can add “0” for hours<10.
I just want to know if I can force arduino to read 0010 as 10?
I just thought that I can store it as char and convert it but maybe there is a simpler way like adding DEC or something similar?

Now that the specific solution has been given, may I ask why you wish to avoid the simple solution of storing HMS values as integers?

aarg:
Now that the specific solution has been given, may I ask why you wish to avoid the simple solution of storing HMS values as integers?

If by that you mean using (YYYY, MM, DD, HH, MM, SS) then it is less clear when you see tables like that. Also you have to add some extra code for time comparision. Doing it my way may not be canonical but is easier for me. You just have to compare two values e.g.

if (startTime < stopTime) ...

and you don’t care about days, months and years.

No, I mean like this excerpt from the DateTime library source:

byte Hour;
 byte Minute;
 byte Second;
 byte Day;
 byte DayofWeek; // Sunday is day 0 
 byte Month; // Jan is month 0
 byte Year;  // the Year minus 1900

Epoch time is also available:

	time_t sysTime;  // this is the internal time counter as seconds since midnight Jan 1 1970 (aka unix time)

The time comparison you show is typical of epoch time handling, which also does permit YYMMDD to be included. It's already well supported so I don't see any reason to re-invent the wheel. It avoids wrap around problems. All your efforts seem to be focused on packing unlike time units into a single int type. It seems like more trouble than it's worth. But, it's your program.

I needed it for easier maintenance of time tables.
I want to ignore date and just use hours/minutes so using unix time doesn't sound like the best way to handle it. Plus I will have no idea what 1584741720 means and setting start/stop times that way would be pain in the a**.
Using bytes as you suggested looks also less clear for human eye but I might be wrong. I was using Arduino for 3-5 times in my life and it will probably stay at similar level for long time so I am not able to dig through all the code in library and figure out how to do some stuff. I just though it is as easy as adding DEC/OCT to Serial.print
Thanks for help and probably I will just try to remember not to add zeroes at the beginning.
Cheers.

This is an event timer? Do you handle day rollover or just prohibit it? For example, you want the difference between Monday, 11:50 and Tuesday, 00:10. You can't just use (0010 - 1150).

There will be no day rollover. It is for ventilation. It will be off during night.

You keep contradicting yourself. If you’re just printing to the serial terminal save the minutes as a byte from 0-59, and the hours from 1-12. Use an if statement to determine when to print a leading 0.

It’s not the most polished code in the world but it shows an example of how you can print the time with leading zeros the easy way.

Take a look at this:

Code:





```
byte hours = 1;

byte minutes = 0;

void setupcolor=#000000[/color] {
 // put your setup code here, to run once:
 Serial.begincolor=#000000[/color];
}

void loopcolor=#000000[/color] {
 // put your main code here, to run repeatedly:
 if(minutes < 59){
   minutes++;
 } else {
   minutes = 0;
 }
 
 if(hours < 12 && minutes == 0){
   hours++;
 } else if(hours == 12 && minutes == 0) {
   hours = 1;
 }
 //==================================================//
 if(hours < 10){
   Serial.printcolor=#000000[/color];
 }
 Serial.printcolor=#000000[/color];
 Serial.printcolor=#000000[/color];
 if(minutes < 10){
   Serial.printcolor=#000000[/color];
 }
 Serial.printlncolor=#000000[/color];
 //==================================================//
 delaycolor=#000000[/color];
}
```

|

OP's not asking about printing with leading zeroes, instead they are asking about reading with leading zeroes.

aarg:
OP's not asking about printing with leading zeroes, instead they are asking about reading with leading zeroes.

I am really confused as to what he's after. If its saved as an int or a byte there wont be any leading zeroes. Is he trying to save it as a string and compare to see if something should turn on? Or is a the first byte in an array 0?

OP. If you want a clear answer we need to know exactly what you are looking for. It's not a shot at you but I want to make sure we're on the same page, otherwise what we say here may just confuse you more.

EDIT: Okay I think I understand what you want now. You want to initialize variables using leading zeros. 0 is the prefix for specifying octal values so it defaults to that. Unfortunately, I don't know of a way to do this. There may be a workaround but I doubt it.

Read here:
integer literal in C and C++ prefixes and suffixes

and read the first couple paragraphs on this page:
C Primer Plus - Variable Prefixes