Login  Register

need help understanding binary numbers w.r.t the hack ALU ng out.

classic Classic list List threaded Threaded
3 messages Options Options
Embed post
Permalink
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

need help understanding binary numbers w.r.t the hack ALU ng out.

stranger
6 posts
This post was updated on Apr 27, 2023; 10:10am.
i'm a bit confused,and would like to understand something,the most-significant-bit(MSB),the first bit/sign bit in a 2s complement number of e.g a 16 bit output "out[16]" would be listed as the "out[15]"? i was confused when "out[0]" didn't work for the control logic of the ng output bit for the Hack ALU,and searched for help and "out[15]" worked,i was confused because i thought the first bit aka "out[0]" would act as the sign bit/MSB
Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: need help understanding binary numbers w.r.t the hack ALU ng out.

Bobber
7 posts
The LSB is indexed at 0 the MSB at length-1. It feels counter intuitive because that means your index starts at the right instead of left

Reply | Threaded
Open this post in threaded view
| More
Print post
Permalink

Re: need help understanding binary numbers w.r.t the hack ALU ng out.

WBahn
Administrator
1541 posts
In reply to this post by stranger
By nearly universal convention, the signals in a multi-bit bus carrying bit patterns that represent numeric values are numbered from lsb to msb with the index of the lsb being zero.

The reason is pretty simple -- and makes it easy to remember.

When you determine the value represented by the bit pattern, you need to multiply each bit by the weight of that bit. Using this convention, the weight of bit n (in unsigned binary) is simply 2^n.

So you have

value = sum{from n = 0 to n = N-1} d[n]*2^n

For 2's complement, the only difference is that the weight of the msb is not 2^(N-1), but rather -(2^N).