1. bit manipulation
- Posted by Allen V Robnett <alrobnett at alumni.princeton.edu> May 25, 2004
- 409 views
My ignorance of programming is astounding, but I think I understand that all information is stored and transferred in bits. What environment would I need to use in order to have a program scan a series of integers, looking for a specific bit pattern, without first having to convert the integers to sequences of bits? I assume that a machine language program would do this naturally. If so, what is the best way to do this without loosing all of the convenience of Euphoria? Allen
2. Re: bit manipulation
- Posted by "Kat" <gertie at visionsix.com> May 25, 2004
- 405 views
On 25 May 2004, at 6:47, Allen Robnett wrote: > > > My ignorance of programming is astounding, but I think I understand that > all information is stored and transferred in bits. What environment > would I need to use in order to have a program scan a series of > integers, If they are real integers, use match() or find()..... > looking for a specific bit pattern, without first having to > convert the integers to sequences of bits? I assume that a machine > language program would do this naturally. If so, what is the best way to > do this without loosing all of the convenience of Euphoria? For a real bitstream, pick something from: http://www.rapideuphoria.com/cgi- bin/asearch.exu?dos=on&win=on&gen=on&keywords=bit+manip Kat
3. Re: bit manipulation
- Posted by "Unkmar" <L3Euphoria at bellsouth.net> May 25, 2004
- 402 views
Um, this will help, Maybe you can figure out how it works and what it means, Or someone else might explain it. It is set on a 8 bit pattern. I can be adjusted to most any size pattern you want. Just a matter of a little imagination. Because integer limitations and multiplier results certain pattern sizes can't be obtained. Max 31-bit integer. so, the first bit pattern size that can't be reached is 37 bits. Because 37 is the first prime after 31. All primes starting from 37 and multiples of those primes can not be reached. It is just a matter of mathematics... you would have to use other methods to match those oddballed pattern sizes. Lucius L. Hilley III- unkmar
function shift_stream(sequence stream) sequence u_bits sequence result -- #80 partly defines the length of your pattern match. u_bits = and_bits(#80, stream) -- Create left most bit pattern. result = stream - u_bits -- remove from existing stream result *= 2 -- shift the stream u_bits /= #80 -- convert to right most bits. u_bits &= 0 if (u_bits[1]) then -- handle overflow bit result = 0 & result else u_bits = u_bits[2..length(u_bits)] end if result += u_bits -- reinsert adjusted bits into stream return result end function ------------------------- integer pattern, f, r sequence i_stream, t_stream, mask, matches pattern = 1 -- Build a test stream of bits to be scanned. i_stream = repeat(0, 255) -- {1, 2, 3, ... , 253, 254, 255} for A = 1 to 255 do i_stream[A] = A end for for A = 1 to 255 do r = rand(255) f = i_stream[A] i_stream[A] = i_stream[r] i_stream[r] = f end for ? i_stream t_stream = i_stream for A = 0 to 7 do -- You can use find() or match() instead of equality for longer patterns. -- If you use match, Your bit pattern can be a string instead of an integer. mask = (pattern = t_stream) -- because I used equality.. it is easier to list all matches not just the first. matches = {} f = find(1, mask) while (f) do matches &= f mask[f] = 0 f = find(1, mask) end while if (length(matches)) then -- I'm only displaying when a match occurs ? {A, matches} -- {shift_amount, matches} -- I'm telling how much I shifted to obtain those matches. end if t_stream = shift_stream(t_stream) end for machine_proc(26, 0) --wait_key() -----------------------------
----- Original Message ----- From: "Allen Robnett" <alrobnett at alumni.princeton.edu> To: <EUforum at topica.com> Sent: Tuesday, May 25, 2004 7:47 AM Subject: bit manipulation > > > My ignorance of programming is astounding, but I think I understand that > all information is stored and transferred in bits. What environment > would I need to use in order to have a program scan a series of > integers, looking for a specific bit pattern, without first having to > convert the integers to sequences of bits? I assume that a machine > language program would do this naturally. If so, what is the best way to > do this without loosing all of the convenience of Euphoria? > > Allen > > > >
4. Re: bit manipulation
- Posted by Craig Welch <euphoria at welchaviation.org> May 26, 2004
- 393 views
Kat wrote: > For a real bitstream, pick something from: > > <a > href="http://www.rapideuphoria.com/cgi-">http://www.rapideuphoria.com/cgi-</a> > bin/asearch.exu?dos=on&win=on&gen=on&keywords=bit+manip That url wrapped in your reply, thus rendering it unclickable. The other party might try to click here: http://tinyurl.com/29d92
5. Re: bit manipulation
- Posted by "Unkmar" <L3Euphoria at bellsouth.net> May 26, 2004
- 402 views
That's why I enjoy newbie questions. It gives me another chance to think outside the box. I had another idea, but when trying to make it real, it fell apart. Lucius L. Hilley III - unkmar ----- Original Message ----- From: "Allen Robnett" <alrobnett at alumni.princeton.edu> To: <EUforum at topica.com> Subject: re: bit manipulation Many thanks to Kat, mic and Unkmar for their replies. I'm sure it must be exasperating to have newbies ask questions that they could have answered for themselves if they had searched the manual, but, in addition to saving me a lot of time, Unkmar has provided an intriguing approach which I have yet to figure out (but I will). Allen
6. Re: bit manipulation
- Posted by "Kat" <gertie at visionsix.com> May 26, 2004
- 407 views
On 25 May 2004, at 19:38, Craig Welch wrote: > > > posted by: Craig Welch <euphoria at welchaviation.org> > > Kat wrote: > > > For a real bitstream, pick something from: > > > > <a > > > > href="http://www.rapideuphoria.com/cgi-">http://www.rapideuphoria.com/cgi-</a> > > bin/asearch.exu?dos=on&win=on&gen=on&keywords=bit+manip > > That url wrapped in your reply, thus rendering it unclickable. Lol, i never made a clickable url! I never wrote any html tags for the url, and there wasn't any in the copy of my email that i recieved back from topica. You run a email client that allows such things, and you admit it online, where people can send you scripted emails that execute code without telling you?? Wow! Hey, let me trojan you, run your mouse over this area! --> Kat
7. Re: bit manipulation
- Posted by Craig Welch <euphoria at welchaviation.org> May 28, 2004
- 394 views
Kat wrote: > > That url wrapped in your reply, thus rendering it unclickable. > > Lol, i never made a clickable url! I never wrote any html tags for the url, > and > there wasn't any in the copy of my email that i recieved back from topica. That's nice, but it was clickable for me. > You run a email client that allows such things, and you admit it online, where > > people can send you scripted emails that execute code without telling you?? No, they can't. Nothing can run from my email client without me initating it. > Wow! Hey, let me trojan you, run your mouse over this area! Do your worst. My email client and I are quite safe. Boy, talk about a red herring. That I can *choose* to click on a typed url has nothing at all to do with Microsoft-like uncommanded behaviour. Oh, since you will now ask, I'm using Mozilla.