2 Replies - 1385 Views - Last Post: 12 March 2013 - 03:24 PM Rate Topic: -----

#1 CrazyPanda  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-March 13

Can't understanding the shifting of alphabet letters using ASCII

Posted 11 March 2013 - 03:20 PM

Can someone please explain how the code/formula below shifts the alphabet letters by a certain number and avoids the error of going over the alphabet if for example the letter to be shifted is Z and the amount to shift is more than 0

For lowercase letters:
NewASCIICode = ((26 + OldASCIICode - Asc("a") + AmountToShift) Mod 26) + Asc("a")


For uppercase letters:
NewASCIICode = ((26 + OldASCIICode - Asc("A") + AmountToShift) Mod 26) + Asc("A")


Would be great if anyone could explain how this is done, I tried googling it, but I just found the code without a proper explanation.

Is This A Good Question/Topic? 0
  • +

Replies To: Can't understanding the shifting of alphabet letters using ASCII

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Can't understanding the shifting of alphabet letters using ASCII

Posted 11 March 2013 - 03:29 PM

Why not do the simple task yourself instead googling it.

Break it down into it constituent parts.
What does each part do?

Now which aspect does the wrap around?
Was This Post Helpful? 1
  • +
  • -

#3 CrazyPanda  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 11-March 13

Re: Can't understanding the shifting of alphabet letters using ASCII

Posted 12 March 2013 - 03:24 PM

View PostAdamSpeight2008, on 11 March 2013 - 03:29 PM, said:

Why not do the simple task yourself instead googling it.

Break it down into it constituent parts.
What does each part do?

Now which aspect does the wrap around?


Thank you for not giving me the solution straightaway :bigsmile: . After a couple of times failing and finding the simpler formula on Wikipedia, I understood how this works.

However, one thing I still not sure about is the +26 at the beginning of the formula, is it really needed in this case? Since 26 Mod 26 = 0, doesn't (26 + AnyNumber) Mod 26 equal to just the AnyNumber? I tried removing it, and the code still works, but I'm not sure if it creates bugs or not, can you clarify if I'm correct or not, please?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1