I don't know how to divide a digit into parts

I have a question about the code Golam Mostafa posted
I would like to use it with a 8 digit number that is "long degok;"

unsigned long test = 0x long(degok);
  byte D0D1 = (byte) (test >> 24) & 0x000000FF;       //D0D1 
  byte D2D3 = (byte) (test >> 16) & 0x000000FF;    //D2D3 
  byte D4D5 = (byte) (test >>  8) & 0x000000FF;      //D4D5 
  byte D6D7 = (byte) test & 0x000000FF;                 //D6D7 
  //----------------------------------
  Serial.println(D0D1, HEX);    //shows: 2 digits
  Serial.println(D2D3, HEX);    //shows: 2 digits
  Serial.println(D4D5, HEX);    //showss: 2 digits
  Serial.println(D6D7, HEX);    //shows: 2 digits

Unfortunately, it shows an error

error: unable to find numeric literal operator 'operator""x'

I think I'm doing something wrong

It doesn't work like that - sometimes @GM gets things a little weird.

Edit: and when I say "it doesn't work like that" I mean "it doesn't work at all".
You'd have to assume the original string was a hex number, and convert it to an unsigned long variable as such, and then...pretend it was really BCD and it all just gets too .... Silly.

What are you doing with the lat/long numbers downstream? In other words, do you need them as numerals for math or a function, or do you need to pass them as characters to some other process/interface?

There are numerous threads on parsing NMEA GPS sentences without libraries. You can use one of those approaches or write your own custom code.

Data lat / long I need to divide in pairs of 2 digits and in this way send them as BCD to the device.
I temporarily did it another way but the problem starts as the data sends 1 and should 01.
the converter suggested above would be a great solution to the problem.

If the value of your pair is less than 10, simply pad with a zero.

aarg:
That's not the same value. It only looks similar since it has the same digits, but it's in a different base.

TheMemberFormerlyKnownAsAWOL:
It doesn't work like that - sometimes @GM gets things a little weird.

Edit: and when I say "it doesn't work like that" I mean "it doesn't work at all".
You'd have to assume the original string was a hex number, and convert it to an unsigned long variable as such, and then...pretend it was really BCD and it all just gets too .... Silly.

Just few days ago, my tutor gave me the following task:

Task: Write an Arduino sketch to show 38 on the CC7SD display unit of the following circuit. Use >> and & operators to get the indices of the digits of the numbers in order to collect the cc-codes from lookup table.
atemp2.png

I uploaded the following sketch into Arduino UNO and showed the result to the tutor; I got the full marks.

byte lupTable[] = {0x3F, ..., 0x71}; //cc-code vs. digit: 0, 1, ..., F
byte ccD0;    //to hold cc-code for the 1st digit (from left) of 38
byte ccD1;    //nyte ccD1;    //to hold cc-code for the 2nd digit (from left) of 38

void setup()
{
    //codes as needed to set the directions of the IO lines
    byte y = 0x38;
    byte indexD0 = y>>4;       //03
    byte indexD1 = y & 0x0F;   //08
    //---------------------------
    ccD0 = lupTable[indexD0];
    ccD1 = lupTable[indexD1];
}

void loop()
{
    PORTD = ccD0;
    digitalWrite(8, LOW);
    digitalWrite(9, HIGH);
    delay(5);
    //------------------------
    PORTD = ccD1;
    digitalWrite(8, HIGH);
    digitalWrite(9, LOW);
    delay(5);
}

atemp2.png

Why go to the bother of calculating ccD1?
You never use it.

And what is a "nyte"?

GolamMostafa:
Just few days ago, my tutor gave me the following task:

How does that relate to anything in this topic?

Danois90:
How does that relate to anything in this topic?

It relates to the Posts quoted in Post#25, which in turn, in turn, ..., turns to the topic of the thread.

TheMemberFormerlyKnownAsAWOL:
And what is a "nyte"?

You change n to b and then nyte will turn to byte.:slight_smile: +k.

Damian01:
Unfortunately, it shows an error

error: unable to find numeric literal operator 'operator""x'

I think I'm doing something wrong

No you are not, you have been given bad advices from GolamMostafa.

Danois90:
No you are not, you have been given bad advices from GolamMostafa.

Sorry! I have not advocated to use my codes (that have used >> and & operators) in his (the OP) application. This is an open Forum -- people have the liberty (under discipline) to express/post their opinions/understandings which should be kept going; otherwise, the discussion Forum would be a cheerless platform. When there is something weird or distracting, the veterans intervene and reveal the solutions.

Probably, you have overlooked the use of % and / operators that I have done being inspired by the posts of @aarg and @Danois90.

I usually do not post working code, but since you have been put on a wild goose chase..

bool extract_lati_longi(char *gps_string, uint32_t &lati, uint32_t &longi)
{
  const char DELIMITERS[] = ",";
  char* token = strtok(gps_string, DELIMITERS);
  uint8_t index = 0;
  lati = longi = 0;
  while ((token != NULL) && (index < 5))
  {
    if (index == 2) lati = (uint32_t)(atof(token) * 100000);
    else if (index == 4) longi = (uint32_t)(atof(token) * 100000);
    token = strtok(NULL, DELIMITERS);
    index++;
  }
  return (lati != 0) && (longi != 0);
}

void setup()
{
  char test[] = "$GNGGA,091609.00,5020.37459,N,01838.41470,E,2,08,0.95,257.5,M,40.4,M,,0000*48";
  uint32_t lati, longi;
  if (extract_lati_longi(test, lati, longi))
  {
    Serial.print("Lat = ");Serial.println(lati);
    Serial.print("Long = ");Serial.println(longi);
  }
  else Serial.println("Extraction failed!");
}

From here you should know what to do.

Thank you all for the answers to my problem. Thanks to you I solved the last problem with GPS and everything works perfectly. Have a nice day. Regards.