Saturday, April 28, 2007

1 byte = how many bits???

You think this is a silly question?? Obviously 8-bits.. Isn't it? Well, if you think it is 8-bits, you are probably wrong. Each byte is made up of 9-bits out of which 8-bits are used for data and the last bit for parity. Always, the number of 1's in the collection of 9-bits should be odd. Thus, parity bit automatically takes the value '1' when number on 1's the the 8-data bits is even and '0' otherwise. As this parity bit is not accessible for the programmer, 1 byte is considered to be collection of 8-bits.

Thursday, April 26, 2007

True in Visual Basic is "-1". Why???

People have been wondering why Visual Basic represents True as -1 whereas most of the other languages consider 1 as true. Here's a brief explanation for why it is like that.

In 2's complement number system, range of numbers that can be represented is -2n-1 to 2n-1 - 1 where n represents the number of bits. For representing True or False, only 1 bit is required and, thus, n = 1. Therefore, according to that formula, a single bit can represent numbers ranging from -1 to 0. 0 is considered as false and -1 is considered as true.