Advertisement

04.22.2008 at 01:41AM PDT, ID: 23342160 | Points: 125
[x]
Attachment Details

Division and multiplying in Two's Complement

Tags: Altera, Quartus, VHDL, VHDL
I would like to create a VHDL coding whereby a certain two's complement value 'n' will be multiplied by 7/8 Is it possible to create such an arithmetic?
In short, what i want is
n X 7/8 = m
if i multiply a two's complement value by 7/8, wouldn't that create an integer? basically why i need this 7/8 value is because when a machine is 7/8 distance from the intended destination, the machine will slow down. Hence the 7/8.

What i thought of was to multiply the two's complement with booth's algorithm and then use the subtraction method to divide the value.any better suggestions?
Anyone can help me out with the coding? thanks.
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: yalawela
Question Asked On: 04.22.2008
Participating Experts: 3
Points: 125
Views: 0
Translate:
Loading Advertisement...
04.22.2008 at 01:46AM PDT, ID: 21409079

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.22.2008 at 01:48AM PDT, ID: 21409082

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.22.2008 at 01:58AM PDT, ID: 21409123

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.22.2008 at 01:59AM PDT, ID: 21409126

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.22.2008 at 02:00AM PDT, ID: 21409133

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.22.2008 at 02:06AM PDT, ID: 21409167

Rank: Master

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.22.2008 at 02:14AM PDT, ID: 21409192

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.22.2008 at 02:15AM PDT, ID: 21409196

Rank: Wizard

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
04.22.2008 at 02:18AM PDT, ID: 21409202

Rank: Guru

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
04.22.2008 at 01:46AM PDT, ID: 21409079

Rank: Master

>> when a machine is 7/8 distance from the intended destination, the machine will slow down. Hence the 7/8.

So it doesn't have to be 100% accurate ? If so, you can divide by 8 first (shift right by 3) and then multiply by 7. You'd lose some of the lower-order bits, but maybe that's no problem, as you'll only compare the value anyway ... you be the judge ;)


The alternative is to convert to a floating point value, in which case you can be more precise, but of course you're working with floating point operations which are usually more expensive.
 
04.22.2008 at 01:48AM PDT, ID: 21409082

Rank: Master

If the value will never be larger than INT_MAX / 7, then you can of course multiply first, and then divide, keeping the exact value (rounded to an integer).
 
04.22.2008 at 01:58AM PDT, ID: 21409123

Rank: Guru

Hello yalawela,

n * 7/8
= n * (8-1)/8
= ((n * 8) - n )/8
= ((n<<3) - n )/8
= ((n<<3) - n )<<3

Regards,
sunnycoder
 
04.22.2008 at 01:59AM PDT, ID: 21409126

Rank: Wizard

((n<<3)-n)>>3
 
04.22.2008 at 02:00AM PDT, ID: 21409133

Rank: Guru

ooops las step should have been >> instead of <<
((n<<3) - n )>>3
 
04.22.2008 at 02:06AM PDT, ID: 21409167

Rank: Master

Note that n can't be larger than INT_MAX / 8 with those formulas (as I noted earlier).
 
04.22.2008 at 02:14AM PDT, ID: 21409192

Rank: Guru

Both methods have their pro and cons ...

For n < 8
(n/8) * 7 would give you inaccurate results!!

 What I and ozo tried to demonstrate here was low cost and low effort method for doing it. If value of n is a concern then use more storage!! If you are using a soewhat recent processor which has an FPU then even floating point operations wont be expensive.
 
04.22.2008 at 02:15AM PDT, ID: 21409196

Rank: Wizard

Less chance of overflow, but rounding differently
n-(n>>3)
 
04.22.2008 at 02:18AM PDT, ID: 21409202

Rank: Guru

ozo,

>n-(n>>3)
Niceeee!!

sunnycoder
 
 
20080716-EE-VQP-33 / EE_QW_2_20070628