In this paper, we studied the problem of beam alignment for millimeter wave (mmWave) communications, in which we assume a hybrid analog and digital beamforming structure is employed at the transmitter (i.e. base station), and an omni-directional antenna or an antenna array is used at the receiver (i.e. user). By exploiting the sparse scattering nature of mmWave channels, the beam alignment problem is formulated as a sparse encoding and phaseless decoding problem. More specifically, the problem of interest involves finding a sparse sensing matrix and an efficient recovery algorithm to recover the support and magnitude of the sparse signal from compressive phaseless measurements. A sparse bipartite graph coding (SBG-Coding) algorithm is developed for sparse encoding and phaseless decoding. Our theoretical analysis shows that, in the noiseless case, our proposed algorithm can perfectly recover the support and magnitude of the sparse signal with probability exceeding a pre-specified value from O(K 2 ) measurements, where K is the number of nonzero entries of the sparse signal. The proposed algorithm has a simple decoding procedure which is computationally efficient and noise-robust. Simulation results show that our proposed method renders a reliable beam alignment in the low and moderate signal-to-noise ratio (SNR) regimes and presents a clear performance advantage over existing methods.Index Terms-Millimeter wave (mmWave) communications, beam alignment, sparse encoding and phaseless decoding.