By Benjamin Pimentel

The tech sector closed higher Tuesday, as gains in shares of Microsoft Corp. and Yahoo Inc. powered the group into positive territory in a volatile trading session.

After struggling in the red earlier the day, the Nasdaq Composite Index (RIXF) battled its way back into the black, as the tech-heavy benchmark added 0.4% to close at 1,975.5, to post a second straight day of gains.

The sector got a boost from Microsoft (MSFT) which rose 1.6% to close at $23.47, while Yahoo (YHOO) gained 1.3% to close $17.22.

The Morgan Stanley High Tech 35 Index (MSH) and the Philadelphia Semiconductor Index (SOX) also each gained a fraction.

The sector also got a lift from other major players, including Hewlett-Packard (HPQ), Oracle Corp. (ORCL) and Dell Inc. (DELL).

But other major companies posted declines, including Google Inc. (GOOG), Intel Corp. (INTC) and IBM Corp. (IBM).

Big Blue announced Tuesday that it will buy software company SPSS Inc. (SPSS) in a $1.2 billion deal.