View Full Version : Decimal to Binary Conversion
schlaray
- 23rd December 2006, 02:53
I recently found a short simple algorithm to convert decimal to binary. Alas, it requires raising a number to a power. In Basic Basic, this notation was n^p. I have checked the math operators over and over in PBP and could not find this operator. The ^ is a bitwise exclusive or.
I require a simple program to convert a 1 to 3 digit decimal number to an eight bit binary number.
Archangel
- 23rd December 2006, 08:08
Hi schlaray,
Are you asking how to display a number in a different format?
You can store a number in a variable and display it as you want using the BIN, DEC, or HEX modifiers - see page 143 PB PRO manual and it will display in whichever format you choose. Hope this helps. JS
paul borgmeier
- 23rd December 2006, 10:10
It's not clear what you are trying to do. Study what Joe has proposed. In case you really want to do this ....
' n^p (n to the power of P)
' n = 2
' p = 5
' x = 2^5 = 32
' in PBP
x var byte
p var byte
p = 5
x = 1
x = x << p ' x = 32
' or
' n = 10
' p = 3
' x = 10 ^ 3 = 1000
' in PBP
x var word
y var byte
p var byte
x = 1
for y = 1 to p
x = x * 10
next y
' x = 1000
Acetronics2
- 23rd December 2006, 10:55
I require a simple program to convert a 1 to 3 digit decimal number to an eight bit binary number.
Hi,
First: note 8 bits binary number has a 255 ( decimal ) limit ... not 999 !!!
Second : your pics only works ( internally ...) with binary ...
Soooo, you already have what you're looking for !!!
as Joe says, it's just a displaying question ...
Read Manual page 93+ for further info.
Alain
schlaray
- 23rd December 2006, 14:58
Pages 93 and 143 explains it all. Thank you all. Thats the way we speak in South Brooklyn.
Schlaray.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.