please help... really stuck

I understand this is an assignment help, i just need a little push in the right direction, dont need anyone to do the actual code or anything. just looking for an explanation.
Cheers guys. thanks in advance.

1) how do I sign extend?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  void binary(int number)
{
    string result = "";
    do
    {
        if ( (number & 1) == 0 )
            result += "0";
        else
            result += "1";

        number >>= 1;
    } while ( number );


    for( int i = 0; i < (8 - result.length()); i++)
{
        result[i] += "0";
}
        cout << result;
        return;
}


2) how to make it so that if decimal is greater that 128, after it crosses 128, the most signficant bit, if 0, just convert it to hex, else if the most significant bit is 1, then make it 10000000 0.... so it is split into two and then convert the two into hex.
e.g.
128: 81 0
129: 81 1
130: 81 2
11224: d7 58
112244: 86 ec 74
Last edited on
Topic archived. No new replies allowed.