Streda Formula for the Hofstadter–Wilson–Dirac Model in Two and Four Dimensions