![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
|
Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
br> br> |
| |||||||
![]() |
| | Thread Tools | Display Modes |
| | #1 (permalink) |
| Guest | Convert Decimal to Binary Hi, Is there a possibility with Windows Power Shell to convert from decimal to binary? Like the "decbin" Function in PHP. |
My System Specs![]() |
| | #2 (permalink) |
| Guest | Convert from decimal to binary Hi, Is there a possibility in Windows PowerShell to convert from decimal to binary? Like the "decbin" function in PHP... |
My System Specs![]() |
| | #3 (permalink) | ||||||||||||
| Guest | Re: Convert Decimal to Binary Try: # convert 192 to binary form PS > [Convert]::ToString(192,2).PadLeft(8,"0") 11000000 ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||
My System Specs![]() | |||||||||||||
| | #4 (permalink) | ||||||||||||
| Guest | Re: Convert from decimal to binary "Cerox" <Cerox@xxxxxx> wrote in message news:63C444F0-B3DD-4BF8-9907-C8620A243E78@xxxxxx
function decbin([int]$num) { $i = 0 $bin = "" do { $bin = "$($num % 2)$bin" $num = [Math]::Truncate($num / 2) if (++$i % 4 -eq 0) {$bin = " $bin"} } while ($num -gt 0) $bin } The one tricky part is using the Truncate method. You would think that you could just use integer division within PowerShell but noooo. It uses banker's algorithm rounding so odd nums round up and even's round down. Considering that not many bankers will ever use PowerShell I have no idea why they chose that form of rounding or rounding at all! It seems like to me that integer division should just truncate like it does in C. -- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
| | #5 (permalink) | ||||||||||||
| Guest | Re: Convert Decimal to Binary "Shay Levi" <no@xxxxxx> wrote in message news:8766a944211d48ca48372ab37582@xxxxxx
-- Keith | ||||||||||||
My System Specs![]() | |||||||||||||
| | #6 (permalink) | ||||||||||||||||||||||||
| Guest | Re: Convert from decimal to binary Added to my library ![]() ----- Shay Levi $cript Fanatic http://scriptolog.blogspot.com
| ||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||
| | #7 (permalink) | ||||||||||||||||||||||||||||||||||||||||||||||||
| Guest | Re: Convert from decimal to binary On Feb 28, 12:55*pm, "Keith Hill [MVP]" <r_keith_h...@xxxxxx_spam_I> wrote:
ps> [convert]::ToString(16, 2) 10000 and the reverse conversion is done with: ps> [convert]::toint32("10000", 2) 16 For padding with zeros, use: ps> [convert]::tostring(16, 2).padleft(8, "0") 00010000 Admittedly ToString() is not the first place i'd look for this either ;-) - Oisin | ||||||||||||||||||||||||||||||||||||||||||||||||
My System Specs![]() | |||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| convert older binary *.reg to Vista *.reg? | Jrz | Vista General | 6 | 12-14-2007 12:58 PM |
| Stock Gadget decimal places | Qualnhick | Vista General | 0 | 11-24-2007 10:04 AM |
| PInvoke and Decimal to Binary Conversion | Joris van Lier | PowerShell | 2 | 05-04-2007 05:48 PM |
| How to embed manifest in TCL binary? - mt.exe corrupting my binary | Kshitij | Vista General | 0 | 02-14-2007 04:42 PM |
| Convert Byte to Binary | perimere | PowerShell | 2 | 02-05-2007 10:08 AM |