Just another Perl shrine PerlMonks

### Re^8: Can I access and use UV types from perl?

by Don Coyote (Hermit)
 on Nov 18, 2019 at 00:52 UTC Need Help??

ohhhh whaaat, I absolutely had my answer on preview for this one and then I knocked my pc off luls...

in essence, I was looking at the integers -8 .. 7 were constructed from the 4 bits rather than how the operation of additon occured upon them.

However, the outcome is that integers as we see them are of two subsets.

The signed integers are composed of a full mask split into a significant bit mask and the complement, the integer being derived from the difference of the component mask to the highbit mask.

The unsigned integers are composed of a full mask split into two, a full mask and its complement (a no-mask), the integer being derived from the differnce of the full mask to the complement mask.

Then there are the unused integers, of the type displayed in the example above Re^6: Can I access and use UV types from perl?. That is where the masks are of a size such that the mask and its complement fills the size of the data providing the integer, and not being 1 or 0 on either side. For example, equal sizes.

An example of the masking to produce integers.

complement mask - sigbitmask + complement mask - sigbitmask 0111 - 1000 + 0111 - 1000 c) 1110 + 0101 0110 - 1000 + 0101 - 0000 (6) - (8) + (5) - (0) (-2) + (5) = 3

Example c number used, taken from Re^7: Can I access and use UV types from perl?, but this works with the others too.

So integers are what we think they are, the difference of pairs of natural numbers.

Replies are listed 'Best First'.
Re^9: Can I access and use UV types from perl?
by dave_the_m (Monsignor) on Nov 18, 2019 at 09:24 UTC
You seem to be over-complicating things. In a computer, registers and memory words hold a collection of bits (e.g. 64 bits). How we interpret those bits is up to the programmer and/or the CPU's ALU. One common way is to treat the bit pattern as as an unsigned binary number. Another common way is to treat them as a two's complement signed value - where values with the high bit set are treated as negative numbers from the point of view of comparisons etc. Other possibilities in the past have included just using one bit as a sign bit, and using one's complement.

The big advantage of two's complement as a way of representing negative numbers is that they can be added and subtracted exactly the same way as unsigned numbers, the only differences being when the overflow flag on the ALU should be set.

But we now seem to be a long way off from anything that has to do with perl.

Dave.

I have just read up on two's complement and one's complement through the link to wikipedia provided by haukex. I had not realised there was a two's complement representation as well as operation, and when I suggested the masking ideas, that the numbers being masked to produce the decimal representation were in two's complement representation. It just seemed to work.

I may have been a little off the mark, when suggesting these were some kind of unused integers, yet I feel it is too early to dismiss the idea as just an outdated one's complement runoff.

I really got a lot out of this thread and the responses from everybody have been very helpful and informative. It is exciting to find out new stuff and expand my knowledge. I try to keep it Perl, but the nature of computers is that it is all related in some manner.

Perl may be DWIM, but WDIM? :)

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11108846]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2022-05-20 16:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Do you prefer to work remotely?

Results (75 votes). Check out past polls.

Notices?