Solved

A question about 'Words'

Posted on 1998-10-28
5
162 Views
Last Modified: 2010-04-16
Hi,

I'm wondering if someone could give me an example of how I can divide a memory word containing the binary representation of an integer into fields of four bits and have each field represent a queue element.Also, how would I decompose an integer into an array of 4 bit integers using MOD and DIV? My text has absolutely no information regarding this and it's becoming frustrating.

I'm barely starting learning this so any help would be appreciated.

Best regards,

Pyramid
 
0
Comment
Question by:Pyramid
5 Comments
 
LVL 5

Expert Comment

by:scrapdog
Comment Utility
How is the word stored?  As an actual word or as a string of 0s and 1s?

Do you want everything to be represented in binary (0s and 1s) using strings?
0
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
Comment Utility
Assuming by word you mean an unsigned 16 bit integer then you do it like this (in pascal - assuming array element 0 is in the most significant four bits of the word):

function GetArrayItemFromWord(ArrayWord : Word; Index : Integer) : Integer;

begin
  GetArrayItemFromWord := (ArrayWord AND ($F000 SHR (Index - 1) * 4)) SHR  (Index - 1) * 4;
end;

or using DIV and MOD

function GetArrayItemFromWord(ArrayWord : Word; Index : Integer) : Integer;

begin
  GetArrayItemFromWord := (ArrayWord DIV ($1000 SHR (Index - 1) * 4)) MOD $10;
end;

I leave the remaining exercise of applying this technique to represent a queue to your homework (hint each field will most likely be used as an index (1 to 15)).

Cheers,

Raymond.
0
 
LVL 12

Expert Comment

by:rwilson032697
Comment Utility
Oops - Some corrections...

Proposed Answer
    From: rwilson
                                                                 Date: Wednesday, October 28 1998 - 05:20PM PST

    Assuming by word you mean an unsigned 16 bit integer then you do it like this (in pascal - assuming array element 0
    is in the most significant four bits of the word):

    function GetArrayItemFromWord(ArrayWord : Word; Index : Integer) : Integer;

    begin
      GetArrayItemFromWord := (ArrayWord AND ($F000 SHR (Index * 4))) SHR  (Index * 4);
    end;

    or using DIV and MOD

    function GetArrayItemFromWord(ArrayWord : Word; Index : Integer) : Integer;

    begin
      GetArrayItemFromWord := (ArrayWord DIV ($1000 SHR (Index * 4))) MOD $10;
    end;

Raymond.
0
 
LVL 3

Expert Comment

by:vikiing
Comment Utility
I think you need to get that integer divided into four groups of 4 bits each. I believe this is the simples way:

Var
     g1, g2, g3, g4: integer;  ('byte' or 'shortint' can serve)
     n: integer;
Begin
     n:=x   <--   'x' is the integer you wanna divide
     g1:=n and 15;  n:=n shr 4;
     g2:=n and 15;  n:=n shr 4;
     g3:=n and 15;  n:=n shr 4;
     g4:=n and 15;

The operation of "and"-ing leaves the lower 4 bits of "n", putting them at g1. After that, "n" is shifted to right 4 places, getting rid of the older bits, and putting the following 4 bits at rightmost position. Once again, g2 takes those bits; and the same for g3 and g4.

0
 

Author Comment

by:Pyramid
Comment Utility
Hi,
Sorry about not replying quickly. The information has helped greatly.

Thanks!!

Pyramid
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Server side business logic 5 350
Consuming Server Sent Event (DOM events) in Delphi 1 745
Youtube stream inside Delphi 1 1,428
Compare of Excelsheets 41 360
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now