What does Padding mean?

Really simple question but sometimes I've seen the word Padding used and always wondered what it really meant. For example if I had a string and what ever the input was I wanted to pad it to 32 characters, what does that mean?

Thanks
Edit: and padding of output strings (which is prob what you were asking about in the first place?)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <iomanip>
using namespace std;

int main(){
    int x = 12;

    cout << "x = " << x << " (no padding)\n"
         << setfill('0') // fill char is space by default
         << "x = " << setw(8) << x << " (padded with leading 0s)\n"
         << left // numbers are right aligned by default
         << "x = " << setw(8) << x << " (padded with trailing 0s)\n";

    return 0;
}


x = 12 (no padding)
x = 00000012 (padded with leading 0s)
x = 12000000 (padded with trailing 0s)

Also...

In the C++ (and C) case, the term padding usually turns up in connection with memory alignment of data structures.

Data structure alignment
http://en.wikipedia.org/wiki/Data_structure_alignment

Memory alignment and padding
http://www.cplusplus.com/forum/articles/31027/

A Query Regarding Structure Alignment
http://www.cplusplus.com/forum/beginner/63914/

But it can also turn up in connection with cryptography and hashing, when an algorithm requires data to have a size which is a multiple of some block size. For example, AES has a block size of 8 bytes, so input data has to be padded to a multiple of 8 bytes before encrypting with this alogorithm.

Padding (cryptography)
http://en.wikipedia.org/wiki/Padding_%28cryptography%29

And there is, of course, padding in the sense of layout. As used in CSS, etc.

CSS Padding
http://www.w3schools.com/css/css_padding.asp

Andy
Last edited on
Topic archived. No new replies allowed.