Original Article Date: Sep 8, 2003
This is a re-write of an older article and explores how you can calculate the decimal equivalent of a binary number with an slant towards raster imagery. Although not really MicroStation stuff,it may help you understand what 1010 and 1101 really means. (With special thanks to the guy I'm married to for explaining this stuff to me!)
A bit is the smallest unit of information that is understood by a computer and is either on which is represented by the number 1 or off which is the number 0.
Value
No. of Bits
No. of Colours
2^{0}
0
1
NULL
2^{1}
2
2^{2}
4
00
2^{3}
3
8
000
2^{4}
16
0000
2^{5}
5
32
00000
2^{6}
6
64
000000
2^{7}
7
128
0000000
2^{8}
256
00000000
2^{16}
18
65,536
000000000
2^{24}
24
16,777,216
Got it?
Note, even though the above chart shows 0's in the last column - it could also be 1's or any combination of 0's and 1's.In an 8 bit image, each pixel is described as having 1 of a possible 256 colours which is composed of eight 0's and 1's to represent that colour number in the palette. Similarily, a 4-bit image would have a maximum colour count of 16.
Image Type
1 Bit
4 Bit
8 Bit
24 Bit
16 Million
In 4 bit image each pixel is described by four values which in turn represents one colour from a total of 16 available colours. The binary number of each colour is as follows:
Binary Number
Colour Number
0001
0010
0011
0100
0101
0110
0111
1000
1001
9
1010
10
1011
11
1100
12
1101
13
1110
14
1111
15
So, how are the colour numbers "calculated" from the binary number? Actually it's easier than you may think. The following table shows the place values for the binary numbering system and it's decimal equivalents. This information will be then be used to calculate the the actual colour number.
Digit Position
Binary
Decimal Equivalent
So, using the above information, the binary number 0110 can be converted as follows:
On/Off Status
Off
On
Adding the decimal values, we get 0 + 4 + 2 + 0 = 6 which is the final answer.One more example:
In this case the colour number is 8 + 4 + 0 + 1 = 13To sum things up, you can calculate the decimal value of a 4-bit binary number, with this little formula:Decimal Number = 2^{3} + 2^{2} + 2^{1} + 2^{0}Remember though, that if the the place value is a 0, it's essentially turned off and ignored. Also, any number raised to the power of zero is always one. Likewise, any number raised to the first power is the number of the base itself.
AskInga Article #47