Uploaded by vicvonvyac

SUMMARY ON MANIPULATING BITS.pdf

advertisement
SUMMARY ON MANIPULATING BITS
The chapter mainly focuses on manipulating bits to use in our form of work.It usually helps
us in finding the encoded bits and look at bits as we may know that c code is not something
a processor can execute.
So firstly the most basic and important thing we need to know are gdb and gcc. These two
are used to locate ascii strings in the memory of the processor,mainly we need to compile
the code using gcc then using -g we need to open the debugging option. This debugging
option is used by GDB to correlate the C abstractions.We will know we are in gdb with the
prompt (gdb) on the start of the line . Here is an example of the use of gdb and a few
commands we can use in gdb. Code source: GRL book.
​(gdb) l
1
#include <stdio.h>
2
int main() {
3
char sample[20] = "Hello World\n";
4
printf("%s",sample);
5
return 0;
6
}
7
(gdb) b 4
Breakpoint 1 at 0x40052b: file helloworld.c, line 4.
(gdb) r
Starting program: /nfsdirs/home4/home4/fac4/mtheys/mybook/a.out
Breakpoint 1, main () at helloworld.c:4
4
printf("%s",sample);
In this code the user sets a breakpoint at 4 , this means the code stops just after
line 3 and before the execution of line 4.Now the user runs the code using “r” and
as we may observe it stops running at line 4 due to the breakpoint. After this we
may want to know what is stored in a certain place , we can find this using x/nf
location sample, in this default one n resembles no of items we want to check of
the type “f” we mentioned in a certain “location”. Image source : GRL
gdb
command
gdb
shortcut
Behavior
Run
r
Executes the program
break n
bn
Set breakpoint at line n of the C code
List
l
List the program
x/nf location
Examine n items of type f starting at address
location
These are the main gdb commands and their behaviours.
Now one of the main parts of manipulating bits are ​bitwise operators​ which are very much
similar to the C code operators like and, or etc.For AND we use “&”, for OR we use “|” , for
XOR we use “^”, for complement we use “~” , for shift left we use “<<” and for shift right we
use “>>”. Notice that AND,OR,XOR require two operands,^ requires one operand , finally left
shift and right shift requires just one operator and a number we can use as a starting point to
shift from.
ARITHMETIC OPERATIONS:
Arithmetic operations are also going to be used in manipulating bits, for example use of
addition,subtraction, and multiplication is significant during common encodings of numbers.
Download