f



Skybuck presents ShiftLeft( Left, Right, Shift ) and ShiftRight( Right, Left, Shift )

Hello,

I think these two functions will come in very handy to solving the "write 
longword bits" problem.

ShiftLeft( Left, Right, Shift )
ShiftRight( Right, Left, Shift )

Shifting with extra inputs is what is required to solve it nicely.

// Begin of Code ***

program Project1;

{$APPTYPE CONSOLE}

{

Skybuck presents ShiftLeft( Left, Right, Shift ) and ShiftRight( Right, 
Left, Shift )

version 0.01 created on 5 may 2008 by Skybuck Flying.

Be carefull though, the shift parameter must be 0 to 31.

}

uses
 SysUtils;

// make overloaded versions for easy coding
// display in big endian.
procedure WriteBitPattern( const ParaByte : byte ); overload;
type
 TbitRange = 0..7;
 TbitSet = set of TbitRange;
var
 vBit : TbitRange;
begin
 for vBit:= 0 to 7 do
 begin
  if vBit in TbitSet(ParaByte) then
  begin
   write('1');
  end else
  begin
   write('0');
  end;
 end;
end;

procedure WriteBitPattern( const ParaWord : word ); overload;
type
 TbitRange = 0..15;
 TbitSet = set of TbitRange;
var
 vBit : TbitRange;
begin
 for vBit:= 0 to 15 do
 begin
  if vBit in TbitSet(ParaWord) then
  begin
   write('1');
  end else
  begin
   write('0');
  end;
 end;
end;

procedure WriteBitPattern( const ParaLongWord : longword ); overload;
type
 TbitRange = 0..31;
 TbitSet = set of TbitRange;
var
 vBit : TbitRange;
begin
 for vBit:= 0 to 31 do
 begin
  if vBit in TbitSet(ParaLongWord) then
  begin
   write('1');
  end else
  begin
   write('0');
  end;
 end;
end;

function ShiftLeft( Left : longword; Right : Longword; Shift : longword ) : 
longword;
asm
 shld eax, edx, cl
end;

function ShiftRight( Right : longword; Left : longword; Shift : longword ) : 
longword;
asm
 shrd eax, edx, cl
end;

procedure Main;
var
 vLeft : longword;
 vRight : longword;
 vShift : longword;
 vResult : longword;
begin
 writeln('program started');

 for vShift := 0 to 31 do
 begin
  vLeft := 0;
  vRight := 1 + 0 + 8 + 0 + 32 + 2147483648;
  vResult := ShiftLeft( vLeft, vRight, vShift );
  Writeln( 'ShiftLeft vLeft: ', vLeft, ' vRight: ', vRight, ' vResult: ', 
vResult );
  WriteBitPattern( vLeft ); write( ' ' );
  WriteBitPattern( vRight ); write( ' ' );
  WriteBitPattern( vResult ); writeln;
  Writeln;
 end;

 for vShift := 0 to 31 do
 begin
  vLeft := 1 + 0 + 8 + 0 + 32 + 2147483648;
  vRight := 0;
  vResult := ShiftRight( vRight, vLeft, vShift );
  Writeln( 'ShiftRight vRight: ', vRight, ' vLeft: ', vLeft, ' vResult: ', 
vResult );
  WriteBitPattern( vRight ); write( ' ' );
  WriteBitPattern( vLeft ); write( ' ' );
  WriteBitPattern( vResult ); writeln;
  Writeln;
 end;

 writeln('program finished');
end;

begin
 try
  Main;
 except
  on E:Exception do
   Writeln(E.Classname, ': ', E.Message);
 end;
 readln;
end.

// *** End of Code ***

Bye,
  Skybuck. 


0
BloodyShame (326)
5/5/2008 4:47:46 PM
comp.arch 7611 articles. 0 followers. carchreader (32) is leader. Post Follow

0 Replies
494 Views

Similar Articles

[PageSpeed] 25

Reply:

Similar Artilces:

what does SHIFT-left-or-right of up-down-left-right do?
Well, I know about shift up-and-down: shift-right ("red" or whatever) up and down on choose-box, HIST, things like that, take the cursor all the way to the beginning or the end. shift-left ("white") on up and down scroll the screen-full up or down (the FIRST such click *stupidly* goes to the final CURRENTLY-ON-SCREEN choice or whatever (meaning TWO double-button-pushes to scroll-down that FIRST time.) What are some of the OTHER possibilities, ie with the left and right arrows? Oh, apparantely undocumented, I've found (via mistaken key-pushes) that RIGHT-arrow will do a SWAP (on stack), and that an UP-arrow gets you into HIST (that HIST is *one nice feature*!) Other tricks with those arrows? Thanks! David David Combs wrote: > Well, I know about shift up-and-down: > > shift-right ("red" or whatever) up and down on > choose-box, HIST, things like that, take the > cursor all the way to the beginning or the end. > > shift-left ("white") on up and down scroll the > screen-full up or down (the FIRST such click > *stupidly* goes to the final CURRENTLY-ON-SCREEN > choice or whatever (meaning TWO double-button-pushes > to scroll-down that FIRST time.) > > > What are some of the OTHER possibilities, ie with the > left and right arrows? > > > Oh, apparantely undocumented,...

shift left, shift right
Hello, Is there any command to shift left or right a vector ? thanks for your reply. patrice: <SNIP ...Is there any command to shift left or right a vector... a hint: help circshift us Try these: 4.1 Vectors To shift and rotate the elements of a vector, use X([ end 1:end-1 ]); % shift right/down 1 element X([ end-k+1:end 1:end-k ]); % shift right/down k elements X([ 2:end 1 ]); % shift left/up 1 element X([ k+1:end 1:k ]); % shift left/up k elements Try this link: <http://www.cs.huji.ac.il/course/2003/impr/matlab/MatlabTip.pdf> -TRO patrice wrote: > > > H...

Left Shift / Right Shift Operators
Hi, Is there any way to catch the losing bit occurring due to Right Shift Operator ? e.g int a = 5 ; a = a >> 1 ; // // a is now 2 and the least significant bit is lost // // I want this solution for the question: "How to find if the number is even or odd using only "<<" or/and ">>" operators ?" On Thu, 29 Nov 2006, Santosh Nayak wrote: > > Is there any way to catch the losing bit occurring due to Right Shift > Operator ? int a = 5; int lost_bit = a & 1; a = a >> 1; /* now lost_bit holds the lost bit */ > ...

Java left shift and right shift operators.
I have a problem where I have to do left shift and right shift. Long N; int shiftby; output = N >> shiftby; Above N is shifted right. Example if N=11101101 [binary value] will become: 1110110 when shiftby=1; will become: 0111011 when shiftby=2; will become: 0011101 when shiftby=3; will become: 0001110 when shiftby=4; will become: 0000111 when shiftby=5; will become: 0000011 when shiftby=6; will become: 0000001 when shiftby=7; When I want to shift left I can use output = N << shiftby; //[Not change in sign "<<" instead of ">>"] Above N is shifted left. Example if N=11101101 [binary value] will become: 111011010 when shiftby=1; will become: 1110110100 when shiftby=2; will become: 11101101000 when shiftby=3; will become: 111011010000 when shiftby=4; will become: 1110110100000 when shiftby=5; will become: 11101101000000 when shiftby=6; will become: 111011010000000 when shiftby=7; I have to use use left shift and right shift to shift Number right/ left depending on value of shiftby if (shift>0) output = N >> shiftby; else output = N << (-shiftby);// working but inefficient. I am using above shift operator many times. I want to get rid of the if then else condition. As If condition takes a lot of time. I want something like output = N >> shiftby; where N is shifted left / right automatically if shiftby is -ve then shift left otherwise shift right. I tried using below function divider=2^shiftby; /...

left shift then right shift an unsigned int
Hello, for the following code: unsigned int var = 0xFF2277F0UL; unsigned char take2 = (var << 8) >> 24; Is there any pitfall about the shift? (get '22' i.e. 34 or '"' as wanted) Thanks and best regards, Wenjie On 11 Jul 2003 04:07:43 -0700, gokkog@yahoo.com (Wenjie) wrote: >Hello, for the following code: > unsigned int var = 0xFF2277F0UL; > unsigned char take2 = (var << 8) >> 24; >Is there any pitfall about the shift? (get '22' i.e. 34 or '"' as wanted) It looks OK to me... -- Bob Hairg...

Distinguish Shift - click left and Shift
Is there a way to distinguish the SelectionType property in a figure for a Shift - click left and Shift - click right? Both result in the SelectionType 'Extend'... Thx "Stefan" <s@m.de> wrote in message <hpkik9$5c3$1@fred.mathworks.com>... > Is there a way to distinguish the SelectionType property in a figure for a Shift - click left and Shift - click right? > Both result in the SelectionType 'Extend'... > > Thx Hi Stefan, if you are in a callback function you can use this example with small changes, taken from the figure prope...

How to do >>(right shift) and <<(left shift) in Matlab?
Hi all, How >>(right shift) and <<(left shift) 2'complement number (both positive and negative integer). Is x>>2 equal to floor(x/4)? And is x<<2 equal to x*4? Best regards, Davy Soho wrote: > Hi all, > > How >>(right shift) and <<(left shift) 2'complement number > (both positive and negative integer). > > Is x>>2 equal to floor(x/4)? > > And is x<<2 equal to x*4? > > Best regards, > Davy > Does bitshift: http://www.mathworks.com/access/helpdesk/help/techdoc/ref/bitshift.html do what you wa...

does PHP read left to right or right to left?
I've two functions. currentHeadline looks in $_GET for a variable called 'image' and prints what it finds. showThumbnail takes an image for a parameter and resizes it before sending it to the screen. But when I do this: <?php showThumbnail(currentImage(), 20, 20); ?> showThumbnail is telling me that it is not being given a file name, and currentImage is printing the file name to the screen. How is that possible? What is the right way to do this? lawrence k wrote: > I've two functions. currentHeadline looks in $_GET for a variable > called 'image' and pr...

LEFT + LEFT vs LEFT + RIGHT
In order to do a full outer join in MySQL one must use a union. Is there any good reason to do SELECT ... LEFT JOIN UNION SELECT ... RIGHT JOIN rather than SELECT ... LEFT JOIN UNION SELECT ... LEFT JOIN with the tables swapped on the latter LEFT JOIN? Paul Lautman wrote: > In order to do a full outer join in MySQL one must use a union. > Is there any good reason to do > > SELECT ... > LEFT JOIN > > UNION > > SELECT ... > RIGHT JOIN > > rather than > > SELECT ... > LEFT JOIN > > UNION > > SELECT ... > LEFT JOIN > ...

Changing x-axis plot from right to left to left to right
Hi, For mathematical reasons, I need to change the way that gnuplots my data along the X axis from right to left to left to right (that is, at the minute it plots from 20 down to 1, not from 1 to 20) I am aware of set xrange reverse but this just inverts the whole graph and displays from 17 .... 1 down along the x-axis rather than plotting the other way round. I'm rather stuck and would appreciate some advice. Regards Jamie On 14.08.2012 17:52, Jamie Rees wrote: > For mathematical reasons, I need to change the way that gnuplots my > data along the X axis from right to left to left to right (that is, > at the minute it plots from 20 down to 1, not from 1 to 20) That makes no sense whatsoever. gnuplot generates some kind of picture. It makes absolutely no difference whatsoever whether a line was drawn from left to right or right to left --- it'll be the same line in the end, consisisting of exactly the same pixels being coloured. So since this doesn't make sense, maybe you should tell us what your actual problem is, so we can find out how that might be solved. On Tuesday, August 14, 2012 6:12:33 PM UTC+1, Hans-Bernhard Br=F6ker wrote: > On 14.08.2012 17:52, Jamie Rees wrote: >=20 >=20 >=20 > > For mathematical reasons, I need to change the way that gnuplots my >=20 > > data along the X axis from right to left to left to right (that is, >=20 > > at the minute it plots from...

How to shift Left or Right in SSE2
How do I do a bitwise shift left or right in SSE2? I would like that each of the 4 Word is shifted left (or right) by a number of n bits. I could only find _mm_srai_epi32 (only right!), which howevere does not do what I want, as it brings in introduce the sign bit. Thanks, Fabio spamtrap@crayne.org writes: > How do I do a bitwise shift left or right in SSE2? > > I would like that each of the 4 Word is shifted left (or right) by a > number of n bits. > > I could only find _mm_srai_epi32 (only right!), which howevere does > not do what I want, as it brings in int...

SPARK left/right shift.
Hi. What's the "correct" way to get access to left/right shift operations for modular types in SPARK? I see from the Checker manual that the proof language is capable of modelling them but then I also see that the Interfaces package isn't predefined. On Jul 21, 10:07=A0am, xorque <xorquew...@googlemail.com> wrote: > Hi. > > What's the "correct" way to get access to left/right shift operations > for modular types in SPARK? The standard shift/rotate functions in Interfaces are overloaded, so not legal SPARK. The way round this is to declare a...

Text widget with mixed left-to-right and right-to-left Unicode text abilities?
Hi, is there one of these? If not I might have a go at writing a simple one of them.... Apologies if this is a FAQ, I did search the archive a bit before posting. Best, Charles. ...

Changing M-<right,left> to C-<right,left>
Hello, I tried to change the word moving behaviour as shown in the post title and could not. Part of my .emacs is below. (global-set-key (kbd "C-z") 'undo) (global-set-key (kbd "C-<right>") 'forward-word) (global-set-key (kbd "C-<left>") 'backward-word) Finally, how could I open a new buffer proportionally in the same window? For instance, if I open a new buffer with C-x 2 and then open the new buffer the window is split in two equal halves. I'd prefer to have it 70%, 30%. TIA, Andre Luiz AndreLTR <andreltramos@gmail.com> writes: > Hello, > > I tried to change the word moving behaviour as shown in the post title > and could not. Part of my .emacs is below. > > (global-set-key (kbd "C-z") 'undo) > (global-set-key (kbd "C-<right>") 'forward-word) > (global-set-key (kbd "C-<left>") 'backward-word) Works for me. Seems the code is not evaluated at all for you, dunno why, presumably something is wrong with your init file. > Finally, how could I open a new buffer proportionally in the same > window? For instance, if I open a new buffer with C-x 2 and then open > the new buffer the window is split in two equal halves. I'd prefer to > have it 70%, 30%. You can use the prefix arg of `split-window-below' to specify window heights in lines, see the doc string. Is that acceptable? ...

FC: control/shift+left/right/up/down not working
Well, in my xterm's I cannot use shift+left, shift+right and so on. If I do, I get: shift+left: 2D shift+right: 2C shift+up: 2A shift+down: 2B control+left: 5D control+right: 5C control+up: 5A control+down: 5B Pressing c-v before pressing the above key combination gives: control-v shift+left: ^[[1;2D and similar for the rest. I don't know how to fix the above problem so that e.g. control+left does what it used to (skip one word to the left). Before upgrading to FC (from RH8) the whole thing worked fine. Any suggestion will be appreciated. :-) Bernhard (this was posted in linux.redhat, not crossposted, sorry) >>>>> "Bernhard" == Bernhard Mogens Ege <bme@hst.auc.dk> writes: > Well, in my xterm's I cannot use shift+left, shift+right and so on. If > I do, I get: > shift+left: 2D > shift+right: 2C > shift+up: 2A > shift+down: 2B > control+left: 5D > control+right: 5C > control+up: 5A > control+down: 5B Well, it figures. Just after posting my problem I managed to solve it. /etc/inputrc is at fault as it does not contain the following lines: "\e[1;5C": forward-word "\e[1;5D": backward-word These enable control+left/right to skip words using bash (readline). This bugreport helped me: :-) http://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=80860 Bernhard ...

Precision of C++ left/right shift operator..
I am using this type of code to do right-shifting, B = 3; data1 = (data + (1 << (B-1))) >> B; data1 seems incorrect when data = -4-8*i.. which means it rounds -1.5 to -1 instead of -2. On the positive side, 1.5 is rounded to 2, which ic correct. For left-shift, it's simply as follows, no pitfalls, am I right? data1 = data << B; Thanks. G Iveco wrote: > I am using this type of code to do right-shifting, > > B = 3; > data1 = (data + (1 << (B-1))) >> B; > > data1 seems incorrect when data = -4-8*i.. which means it > rounds -1.5 to...

left and right shift operations for custom menus
Hi everyone I want to create a custom menu on my HP50g. Reading the electronic user's guide I see that to create a (permanent) custom menu that assigns the functions EXP, LN, GAMMA and ! to the keys F1, F2, F3 and F4 respectively, one enters: {EXP LN GAMMA !} ENTER MENU However a little later in the guide it states that the general form of the list above is: {=93label1=94, function1, ls1, rs1}, {=93label2=94, function2, ls2, rs2},= =85} where "label1" is the name of the soft menu key, funtion1 is the function that will be carried out when the key is pressed and ls1 and rs1 ...

right/left shift + click, mouse wheel scroll
Hello, I am new to this group - have searched ubuntuforums and winehq but haven't found too much related with my problem. Not quite sure this is wine related or xorg.conf related, please let me know if a known issue. The issue is appearing for any recent versions of wine up to current 0.9.45 (have tried on last 5-6 versions), on ubuntu 6.06 and 7.04. My windows app is developed in Borland Delphi and works almost 100% well under wine. The one problem I noticed so far is that is not responding when Shift+clicking on buttons, as expected (under MS Windoes, this opens specific repor...

Problem with cin, cout using shift left and right?
I want to know what problem with cin, cout, overlow operator using shift left and right? Xoomer wrote: > I want to know what problem with cin, cout, overlow operator using > shift left and right? > You've mutli-posted again, please don't. -- Ian Collins. ...

how to locate right slot in a range with right-shifting and offset?
Hi all, Assume I non-uniformally break down a range from 0 to (2^10)-1 into (2^4)-1 blocks. |----|---|------|---|......|--| 0 5 7 (2^10)-1 For a given value x (x may be from 0 to 2^10-1), I would like to locate what block x should be in. For example if x is 6, I want to find the second block (from 5 to 7) in the above figure. ( x is integers). In a technical report, for this task, I see they use the operator: block_address=x >> shift_amount + offset_amount. (>> is right shift). where shift_amount and offset_amount are the same for all values of x. (all ...

Right or Left ?
A simple multimedia setup can be a display monitor with speakers positioned on both sides. Think of this equipment as being on a 'stage' in a theater, and the user as being the 'audience' in that theater. What is called the "left" speaker -- is it the one on the left of the audience (as viewed by the audience), or the one on the left of the stage (as viewed by an actor standing ON the stage, facing out towards the audience) ? mikus Sir: Mikus Grinbergs wrote: > A simple multimedia setup can be a display monitor with > speakers positioned on...

left shift
hii am relatively new to python..was checking out some bit shifting..when i do255<< 24 i get 4278190080whereas in java or c it gives -16777216can someone tell me why this is ?,what should i do if i want theoutput as -16777216 ?dnp:sI wrote a fn to show the binary digits in the number and it gives sameoutput for both numbers(4278190080 and -16777216)def pBinInt(str,i): print str,",int",i,", binary:" print " ", for j in range(31,-1,-1): if(((1 << j) & i) != 0): print 1, else: print 0, print "&...

Left shift
Hi, how is this code working? As per me since aNum is int8 so left shifting aNum by 8 would make it zero, how is it maintaining this? if i left shift it by 32 it becomes zero? unsigned __int8 aNum = 5; printf("%d",aNum << 16); Thanks Keshav -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] Keshav wrote: > Hi, > how is this code working? As per me since aNum is int8 so left > shifting aNum by 8 would make it zero, how is it maintaining this? > if i left shift i...

left, right?
What function returns some number of characters on the right or left of a string? i.e. if I have the string 'filename', is there a command like Left('filename',4) = file? Thanks. asdd12 wrote: > > > What function returns some number of characters on the right or > left > of a string? i.e. if I have the string 'filename', is there a > command > like Left('filename',4) = file? Thanks. >> f='filename' f = filename >> f(1:4) ans = file In article <ef4d6a8.-1@webcrossing.raydaftYaTP>, nospam@nospam.com says... &...