ok, i get it now. so like for n bit representation, we can use only (n-1) bits for values nd 1 is fr sign. is everything in c stored in binary?
Shashank Jain IIIrd year Computer Engineering Delhi College of Engineering On Sun, Aug 7, 2011 at 8:19 PM, Yasir <yasir....@gmail.com> wrote: > @Shashank, You didn't get it properly. > If leftmost bit *0*, then it is a *+ve* number. > If it's *1* then it's a *-ve* number. > > Let's take above example with 16 bit: > a=6 > binary: 0000 0000 0000 0110 (note that leftmost bit is 0, so it's +ve > number) > ~a= 1111 1111 1111 1001 (now leftmost bit is 1, so compiler will treat > it as -ve number.) > > To obtain its *-ve decimal value* you need to calculate it's 2's > complement. (note that the value obtained with 2's comlement would be - > ve). > > > Also you can cross verify that ~a represented above is -7. > Simple math -7 +7 =0; > > 1111 1111 1111 1001 > 0000 0000 0000 0111 > ------------------------------ > 00000000000000000 > > > Kindly, check out following link for more details on 2's complement: > > http://academic.evergreen.edu/projects/biophysics/technotes/program/2s_comp.htm > > Thanks, > Yasir > > > On Aug 7, 6:01 pm, Shashank Jain <shashan...@gmail.com> wrote: > > nd moreover after 2's complement its 0000 0111 which is 7 nd not -7. so > how? > > Shashank Jain > > IIIrd year > > Computer Engineering > > Delhi College of Engineering > > > > > > > > > > > > > > > > On Sun, Aug 7, 2011 at 6:25 PM, Shashank Jain <shashan...@gmail.com> > wrote: > > > so tell me fr any bit representation, 1st bit is for sign only na? > > > > > Shashank Jain > > > IIIrd year > > > Computer Engineering > > > Delhi College of Engineering > > > > > On Sun, Aug 7, 2011 at 6:03 PM, Yasir <yasir....@gmail.com> wrote: > > > > >> 8 bit was taken just for example. It can be 16/32 bit but that won't > > >> make any difference on leading 0's or 1's. > > > > >> On Aug 7, 5:28 pm, Shashank Jain <shashan...@gmail.com> wrote: > > >> > y r we taking 8 bit numbers, i mean dat way we cant go beyond -127 > to > > >> 127? > > > > >> > Shashank Jain > > >> > IIIrd year > > >> > Computer Engineering > > >> > Delhi College of Engineering > > > > >> > On Sun, Aug 7, 2011 at 5:39 PM, Yasir <yasir....@gmail.com> wrote: > > >> > > let say a=6; binary= 0000 0110 > > >> > > b = ~a = 1111 1001 > > >> > > Now when you print value of ~a or b, it is calculating 2's > complement. > > >> > > 1's complement: 0000 0110 > > >> > > 2's complement: 0000 0111 (value = -7) > > > > >> > > Pls check signed bit representation for details. > > > > >> > > On Aug 7, 4:40 pm, Shashank Jain <shashan...@gmail.com> wrote: > > >> > > > bitwise complement operator (~), complements d digits of d input > bt > > >> when > > >> > > i > > >> > > > use it : > > > > >> > > > int a,b; > > >> > > > b=~a; > > > > >> > > > output: its giving o/p such that b= -a-1; > > > > >> > > > why is dat so? > > > > >> > > > Shashank Jain > > >> > > > IIIrd year > > >> > > > Computer Engineering > > >> > > > Delhi College of Engineering > > > > >> > > -- > > >> > > You received this message because you are subscribed to the Google > > >> Groups > > >> > > "Algorithm Geeks" group. > > >> > > To post to this group, send email to algogeeks@googlegroups.com. > > >> > > To unsubscribe from this group, send email to > > >> > > algogeeks+unsubscr...@googlegroups.com. > > >> > > For more options, visit this group at > > >> > >http://groups.google.com/group/algogeeks?hl=en. > > > > >> -- > > >> You received this message because you are subscribed to the Google > Groups > > >> "Algorithm Geeks" group. > > >> To post to this group, send email to algogeeks@googlegroups.com. > > >> To unsubscribe from this group, send email to > > >> algogeeks+unsubscr...@googlegroups.com. > > >> For more options, visit this group at > > >>http://groups.google.com/group/algogeeks?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.