[julia-users] Re: binary string to hex
On Friday, 4 December 2015 16:36:34 UTC, James Gilbert wrote: > > I find bits(a) more useful than bin(a). It enables me to see all the bits > of an integer when experimenting with << and >> to see if I'm doing the > right thing. eg, set the 2nd bit of a byte: > > > *julia> **a = 0b0010* > > *0x02* > > > *julia> **bits(a)* > > *"0010"* > > > *julia> **a = a | (0x1 << 6)* > > *0x42* > > > *julia> **bits(a)* > > *"0110"* > > Looks interesting though when I try to set it back to the original, I get 0x42 a = a | (0x0 << 6) I guess im missing something :) M
[julia-users] Re: binary string to hex
I find bits(a) more useful than bin(a). It enables me to see all the bits of an integer when experimenting with << and >> to see if I'm doing the right thing. eg, set the 2nd bit of a byte: *julia> **a = 0b0010* *0x02* *julia> **bits(a)* *"0010"* *julia> **a = a | (0x1 << 6)* *0x42* *julia> **bits(a)* *"0110"*
[julia-users] Re: binary string to hex
you're binary-or'ing a bit with 0x0, which means you're not going to change it. There's some useful information here: https://en.wikipedia.org/wiki/Bit_manipulation On Friday, December 4, 2015 at 9:47:45 AM UTC-8, Martin Somers wrote: > > > > On Friday, 4 December 2015 16:36:34 UTC, James Gilbert wrote: >> >> I find bits(a) more useful than bin(a). It enables me to see all the bits >> of an integer when experimenting with << and >> to see if I'm doing the >> right thing. eg, set the 2nd bit of a byte: >> >> >> *julia> **a = 0b0010* >> >> *0x02* >> >> >> *julia> **bits(a)* >> >> *"0010"* >> >> >> *julia> **a = a | (0x1 << 6)* >> >> *0x42* >> >> >> *julia> **bits(a)* >> >> *"0110"* >> >> > Looks interesting though when I try to set it back to the original, I get > 0x42 > > a = a | (0x0 << 6) > > I guess im missing something :) > M >
[julia-users] Re: binary string to hex
ahh i see thanks going a = a $(0x1 << 6) reverts back then again I could just initialise it again to default :) tks guys M