Pete Dowson Posted February 2, 2010 Report Share Posted February 2, 2010 This is a short tutorial for those needing to know more about how to deal with bit numbers, and masks, and values to use when setting, toggling or clearing bits. BINARY Binary numbers, the ones actually used in computers, are made up of "bits". Each bit can only be "on" (1) or "off" (0). So, with one bit you can only count 0 then 1. With 2 bits you can count from 0 to 3, via the combination of the two bits, thus: 00 = 0 01 = 1 10 = 2 11 = 3 A binary number can have as many bits as you need, but computers generally have addressable groups of bits, as follows: BYTE = 8 bits, running from 00000000 to 11111111 (decimal 0 to 255). WORD = 16 bits DWORD = 32 bits The addresses known in FSUIPC as "offsets" actually point to BYTES, but any size data may start at that byte address. Note that in decimal, each higher digit in a number is worth 10 times the adjacent one. So Decimal 245 = (2 x 10 x 10) + (4 x 10) + (5 x 1) In Binary the same sort of thing is true, but now each digit is only worth 2 x the adjacent one. So Binary 1101 = (1 x 2 x 2 x 2) + (1 x 2 x 2) + (0 x 2) + (1 x 1) = decimal 13. Okay so far? BIT NUMBERS Documentation like that for Project Magenta often refers to "bit numbers", like "bit 0" or "bit 17". All this refers to is the position of the bit in the overall number. Most usually (but not always) bits are numbered from the bottom, the bit of value 0 or 1. So, in the example of decimal 13 above: 1 1 0 1 the bits, left to right are bits 3, 2, 1 and 0. Using this system of numbering, the VALUE of that bit in the number can be computed as 2 to the power of the bit number, like 2^N (the power should be superscripted, but i don't know how to do that here -- the ^ convention is used in programming languages). Thus. If 2^3 means "2 x 2 x 2", the 13 could be written as 2^3 + 2^2 + 2^0 (note that mathematical convention dictates that a number to the power of zero is always 1). HEXADECIMAL Writing numbers in binary all the time is laborious and error prone, so often a different number system is used -- octal (base 8 ) and hexadecimal (base 16). In today's PCs hex is better because most units are made up of multiple of 4 bits, and 4 bits, as we saw, have the capacity to count from 0 to 15: so 16 values in all. So, whilst you can treat hex numbers as base 16 numbers, with each more significant digit being worth 16 times the adjacent one, in cases where you are really handling bits, as here, you merely need to think of the binary number being divided into groups of 4 bits. The different values of 4 bits, from 0 to 15, are represented in hex like this: Binary 0 0 0 0 = Hex 0 = Decimal 0 Binary 0 0 0 1 = Hex 1 = Decimal 1 Binary 0 0 1 0 = Hex 2 = Decimal 2 Binary 0 0 1 1 = Hex 3 = Decimal 3 Binary 0 1 0 0 = Hex 4 = Decimal 4 Binary 0 1 0 1 = Hex 5 = Decimal 5 Binary 0 1 1 0 = Hex 6 = Decimal 6 Binary 0 1 1 1 = Hex 7 = Decimal 7 Binary 1 0 0 0 = Hex 8 = Decimal 8 Binary 1 0 0 1 = Hex 9 = Decimal 9 Binary 1 0 1 0 = Hex A = Decimal 10 Binary 1 0 1 1 = Hex B = Decimal 11 Binary 1 1 0 0 = Hex C = Decimal 12 Binary 1 1 0 1 = Hex D = Decimal 13 Binary 1 1 1 0 = Hex E = Decimal 14 Binary 1 1 1 1 = Hex F = Decimal 15 So, to convert a binary number to hex you simply divide it into groups of 4 bits (from the bottom, least significant part) and use the above equivalences. For example Binary 1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 1 becomes 1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 1 so it is hex AF2D. The reverse conversion works too. EXAMPLES So, I was asked how we get the hex value "10000" for bit 16 and how we calculate the value "20000000" for bit 29. Now it should be easy for you all: Bit 16 is the 16th bit up counting from 0, so in binary it must be (I've already divided it into 4's to save time): 1 0000 0000 0000 0000. which you can convert to hex as I showed above ---> 10000 Bit 29 is likewise the 29th bit up counting from 0: 10 0000 0000 0000 0000 0000 0000 0000 So, hex 20000000. Of course you don't need to write down all the bits. 29 divided by 4 (the number of bits in a group) is 7 remainder 1, so it has 7 hex 0's after a 2^1 group, and 2^1 = 2. Good flying! Pete 1 Link to comment Share on other sites More sharing options...

steelholland Posted October 5, 2010 Report Share Posted October 5, 2010 "What you get if you don't pay: The ability to run all FSUIPC-dependent application programs, modules and gauges." Dear pete as in the quote above it says what do you get if you dont pay for fsuipc, is there any whay to get a free code? I just want to fly my new add-on. By the way the main game is fs2004 and the add on is airbus a340 proffesional. Thankyou, steelholland. The only reason i ysed this forum is becayse i couldn't contact you in any other way. Link to comment Share on other sites More sharing options...

Aviation BoSs Posted July 23, 2013 Report Share Posted July 23, 2013 thank you, so much for such explanation, very useful Link to comment Share on other sites More sharing options...

Aviation BoSs Posted July 23, 2013 Report Share Posted July 23, 2013 (edited) i like such tutorials :) Edited July 23, 2013 by Aviation BoSs Link to comment Share on other sites More sharing options...

## Recommended Posts

## Create an account or sign in to comment

You need to be a member in order to leave a comment

## Create an account

Sign up for a new account in our community. It's easy!

Register a new account## Sign in

Already have an account? Sign in here.

Sign In Now