Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to write this functions using c

Status
Not open for further replies.

eng_ibrahim

Member level 1
Joined
Nov 21, 2012
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,555
hello ,
i want the solution
1)array has repeated numbers this numbers are scattered how to make it without repeated number using only one for loop
2)write a function to take a byte like this 101100011 and then reverse the byte 110001101 like this
thanks
 

Hi,

Your binary numbers have 9 bits, but a byte has only 8 bits.

In ASM:
Do 8 times
* shift input byte left (bit 7 int carry)
* shift output byte right (carry into bit 0)

Klaus
 

Hi,

Your binary numbers have 9 bits, but a byte has only 8 bits.

In ASM:
Do 8 times
* shift input byte left (bit 7 int carry)
* shift output byte right (carry into bit 0)

Klaus

thanks a lot but i need to do using c
 

Re: write these functions in c

Hello!

1. Your description is fuzzy. Can you give examples?

For example, you want to replace 1 2 2 4 7 5 5 and you want to find 1 2 4 7 5 ?

2. You declare another variable, you take the variable's last bit, put it at the last position of
another variable. Shift the old variable right, shift the new left and that's it.

Dora.
 

Re: write these functions in c

Hello!

1. Your description is fuzzy. Can you give examples?

For example, you want to replace 1 2 2 4 7 5 5 and you want to find 1 2 4 7 5 ?

2. You declare another variable, you take the variable's last bit, put it at the last position of
another variable. Shift the old variable right, shift the new left and that's it.

Dora.

thanks
regarding function one is true that i want to do using only one for loop and thanks a lot for your clarification of second function
 

Tell us if "doraemon" on post #4 is right or not because I am still confused about your question 1).
 

The general solution to your 2nd problem is well known - check out https://graphics.stanford.edu/~seander/bithacks.html.
In the examples for your first problem (and I must admit these really do sound like homework examples to me) the repeated numbers are shown as consecutive - is this always the case? In other words could the numbers be 1 3 5 6 2 3 7 3 2 5 8 1? If so then the solution is a bit different.
Is there a defined range for the values? Again this might influence some possible solutions (i.e. representing the set as bits).
Also I assume that being allowed to use only one for loop also precludes calling functions.
Susan
 

Tell us if "doraemon" on post #4 is right or not because I am still confused about your question 1).

yes ,he is write but i want to do the function using only one for loop
 

Which compiler are you using ?

Am I right ?

You have an array like myArray[5] and it has values like

11001100 00110011 10101010 01010101 11110000

and you want to change it to

00110011 11001100 01010101 10101010 00001111

???
 

Which compiler are you using ?

Am I right ?

You have an array like myArray[5] and it has values like

11001100 00110011 10101010 01010101 11110000

and you want to change it to

00110011 11001100 01010101 10101010 00001111

???

regarding this problem i made it and its code but i didn't know the 1)array has repeated numbers this numbers are scattered how to make it without repeated number using only one for loop For example, replace 1 2 2 4 7 5 5 with 1 2 4 7 5 ?
 

Hello!

Well, there is nothing complicated in doing this. You want to use a single for loop,
then here is the strategy:

- What will happen is that the first time you encounter a repetition, you have
to move all the subsequent bytes by one to the left. The second time, you will
have to move by 2 to the left.

There are many ways to do it. I would use two indexes to the same array.
At fist, index_out = 0, and index_in = 1.
If the bytes at the 2 indexes are equal, then you have to move index_in by one,
and not move index_out.
If they are not equal, then you copy the value of index_in into index_out and you move
both.

Let's try with the example above. I will replace the numbers with letters to avoid
confusion
1st line: position of the pointers
2nd line array

The first 2 characters are not equal, therefore write the second on input pointer+1
0 1
A B B D G E E

Move the pointers by 1 since it was different
1 2
A B B D G E E

The characters 1 and 2 are equal. Therefore move the 3 only and don't write anything
1 3
A B B D G E E

Then the characters 1 and 3 are different. Write character at 3 to output pointer +1
and move both
2 4
A B D D G E E

the characters 2 and 4 are different. Write character at 3 to output pointer +1
and move both.
3 5
A B D G G E E

the characters 3 and 5 are different. Write character at 4 to output pointer +1
and move both.
4 6
A B D G E E E


Pointers of 4 and 6 are equal. and 6 is at the end. You can also remove the
characters after the end of the output pointer.

NB : I didn't try the algorithm, but I would try this way. Note that you should
think about that yourself...

Dora.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top