Knowledge Base
...
Applied PIC Micro Development
PIC Programming

Binary Numbers

6min
synopsis understanding number systems is essential to leveraging the most out of the microcontroller since most of the code you create will involve initializing and working with values, understanding the numerical attributes of the device is essential when initializing values, that may be initialized as a variable which is the most common alternatively, values may be initialized as constant variable values can be worked with and changed this topic is introductory and should be read in conjunction with topics to follow introduction a microcontroller is a binary device, and therefore it works with two values at the base level 1 and 0 the "meaning" of the binary value changes depending on where and how it's used although there are other number types such as integer numbers application 1 and 0 form the base 2 numbering system and the highest value which can be held by a single, 8 bit register is 255 or 11111111 when used in code, ie in the compiler, that number can be represented in a number of ways for example oxff or 'b11111111 although the developer may want to represent a number in any of the following ways, it ultimately comes back to the same when the value is compiled however, it functions in 1's and 0's if a number of larger values is required, then two or more registers can be joined together registers in an electronic context, 1 is high, and 0 is low this can be inverted depending on the application when configuring a register, a 1 sets the register high and a 0 clears the register setting it low even though technically 1 is high and 0 is low, ensure that you read the datasheet thoroughly to ensure what the effect of changing the value port registerswhen configuring the pic ports, there are three registers that need to be configured the direction is controlled by the tris registers, 1 = input and 0 is otuput however, when setting a pin high, it gets set to 1, and 0 clears the pin trisb = 0x00; // all outputs configured for output portb = 0xff; // all outputs set high writing numbers when using numbers in code, they must be written in a way that the compiler understands and can use some examples are shown below numbers and representation 1 or 0 'binary representation of a 1 or zero given a high or low value for positive logic, whereas in negative logic their meaning is inverted 'b10101010 an 8 bt register can be represented as shown left each position however has a set value and designation this designation is used to correspond to specific attributes of a register 255 this is the maximum value of an 8 bit register this is a decimal representation of the binary equivalent 0xff this is the maximum value of an 8 bit register this is a hex representation of the binary equivalent summary in the next section, we will look at different number types and how they are used in code