all these values are the same to Perl.my $value1 = 255; my $value2 = 0377; # 377 octal, equal to 255 decimal my $value3 = 0xff; # FF hex, same as 255 decimal my $value4 = 0b11111111; # also 255 decimal
The only thing for which I can see the conversions you are trying to do to be useful is for input and output of special representations of those numbers. Or, of course, for training purposes but you will not have to use that very often.
I can remember of one single case where I had to do that in Perl, for modeling a game with white and black stones where is was convenient to represent the game board (and the moves) with 16-bit integers, where, for example, a 0 would represent a white stone and 1 a black stone (still, although my program was using heavily the bit-wise operators, I needed binary representation only for the purpose of displaying conveniently debugging information, the program itself did not need it).
The octal representation is sometimes needed for such thing as Unix file permissions. Sometimes you might use bit vectors and need to see what it looks like, or need to visualize individual bits for other low level operations, but it is still rather uncommon in day to day Perl programming to need to use the binary representation of numbers.
In reply to Re: How to convert negative and positive floating points to binary and vice versa
by Laurent_R
in thread How to convert negative and positive floating points to binary and vice versa
by thanos1983
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |