PDA

View Full Version : Objective-C




user582
Apr 12, 2011, 01:27 AM
Hello, am a new to objective-C and this is the question that I have.
This may be a bit confusing. I have two numbers, say
x = 56 = 00111000
y = 50 = 00110010
we can see that there a total of 4 different bits between them. we need to take those bits and fill up part of the 8 bit register. and in the same way take another two numbers ( say there are another 4 bits different in them ) then fill up the remaining part of the 8 bit register. Does anyone know how to do this using objective-c ?



Cromulent
Apr 12, 2011, 03:33 AM
Hello, am a new to objective-C and this is the question that I have.
This may be a bit confusing. I have two numbers, say
x = 56 = 00111000
y = 50 = 00110010
we can see that there a total of 4 different bits between them. we need to take those bits and fill up part of the 8 bit register. and in the same way take another two numbers ( say there are another 4 bits different in them ) then fill up the remaining part of the 8 bit register. Does anyone know how to do this using objective-c ?

Your terminology is very hard to follow. First of all "register" means something completely different to most programmers. Unless you have declared your variables with the register keyword you really have no idea if the data is actually stored in a register or not (unless the platform ABI guarantees it).

Second of all, what do you mean by fill up? Do you mean turn the binary data into all 1's? If so just make the integer 255 (if unsigned) or -127 (if signed). Otherwise you might want to look at things like logical and, xor, or or not. Bit shifting is also useful as well.

Frankly though I have no idea what you are trying to accomplish. Can you explain in a clearer manner please?

dutchchilly
Apr 12, 2011, 04:06 AM
Sounds like you come from Assembly.
Just explain what you are trying to accomplish, perhaps we can help.

I think his 'register' means containers, in our case variables/objects.

user582
Apr 12, 2011, 06:51 AM
k. wen we consider those examples of 50 and 56. in terms of bits, we can see that there are 4 bits that there are 4 different bits between them. let forget abt the register. i want to place these 4 different bits in an array. then lets take another example where those two again have 4 different bits in between them. take those different bits and place them in that array. that array now has 8 bits. now i want to convert those 8 bits in the array to its decimal form.

balamw
Apr 12, 2011, 08:00 AM
How much do you understand the bitwise logic operations in "C"?

http://en.wikipedia.org/wiki/Bitwise_operation

EDIT: It sounds like you are describing two XOR operations and a 4-8 bit combination.

No, actually it sounds like you want to pull off the lower nybble of each and combine them. Is this something like an ASCII -> BCD conversion?

If I have 0x50 and 0x56, the lower nybble (4-bits) is different. Do you want a mask i.e. you would get 0x06 (What is different from 0x50) or an XOR 0x0F. (These values are different).

Here's Wikipedia on masking: http://en.wikipedia.org/wiki/Mask_(computing)

You'll also need to define what you mean by "decimal form"

Let's say you are masking and from 0x50 and 0x56 you get 0x06, you do it again and get 0x06, you shift and combine these to get 0x66. Do you want decimal 66 from this or decimal 6*16+6=102?

B