Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › 32 bit signed binary, and two's compliment
New Posts  All Forums:Forum Nav:

32 bit signed binary, and two's compliment

post #1 of 11
Thread Starter 
i am going though a programming course in pursuit of my software engineering degree now this course really has a lot to do with programming but it is not an actual programming course any way, since it has a lot to do with programming i thought i would ask to make sure i was doing it was doing it right....

converting from decimal to binary is pretty easy but what i am wondering is after you convert to binary, if it is positive you just add zeros in front of it until there are 32 and if it is negative you add ones, right?

and to convert to two's compliment you take the positive signed binary and switch all of the ones to zeros and all of the zeros to ones except one of them, right?
post #2 of 11
Quote:
Originally Posted by phantasmor View Post
converting from decimal to binary is pretty easy but what i am wondering is after you convert to binary, if it is positive you just add zeros in front of it until there are 32 and if it is negative you add ones, right?
Well, the zeros and ones are already there. You're just transcribing them to paper.

Quote:
Originally Posted by phantasmor View Post
and to convert to two's compliment you take the positive signed binary and switch all of the ones to zeros and all of the zeros to ones except one of them, right?
Flip all the bits and then add one. See also Two's complement - Wikipedia, the free encyclopedia
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #3 of 11
Thread Starter 
Quote:
Originally Posted by error10 View Post
Well, the zeros and ones are already there. You're just transcribing them to paper.
lol, yeah i thought so

Quote:
Originally Posted by error10 View Post
Flip all the bits and then add one. See also Two's complement - Wikipedia, the free encyclopedia
yeah i never got that add one, i just leave the right most digit the same

all in all thanks for confirming i am doing it right

oh, and in negative two's compliment... i noticed that it is just the same as negative signed binary, you just flip the binary portion
Edited by phantasmor - 4/18/11 at 11:33am
post #4 of 11
Thread Starter 
oh, how do you convert from two's compliment to binary? if there are zeros to the left, do i just treat everything to the right of the zeros as binary? or is there something more complicated to do?
post #5 of 11
2's complement is the same as in binary when there's only a leading 0. The only difference is that a leading 1 is used to indicate negative numbers.
Secks Machine
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 3.6ghz Gigabyte P35 DS3L BFG 8800gt OC 2gb Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
Samsung F3 1TB Samsung 20x dvd-rw Windows Vista Home Premium 32 Samsung 226bw 22" LCD 
PowerCase
Corsair VX550 Lian Li PC-7 Plus 
  hide details  
Reply
Secks Machine
(13 items)
 
  
CPUMotherboardGraphicsRAM
Q6600 G0 3.6ghz Gigabyte P35 DS3L BFG 8800gt OC 2gb Crucial Ballistix 
Hard DriveOptical DriveOSMonitor
Samsung F3 1TB Samsung 20x dvd-rw Windows Vista Home Premium 32 Samsung 226bw 22" LCD 
PowerCase
Corsair VX550 Lian Li PC-7 Plus 
  hide details  
Reply
post #6 of 11
Thread Starter 
yay! i did it right! my classmates were all doing it wrong then, oh well.....
post #7 of 11
iirc: 00000001 to 2's complement = 1st step ->11111110 2nd step add 1 ->11111111
ShadowForge
(12 items)
 
Defiant
(14 items)
 
CarbonCat
(13 items)
 
CPUMotherboardGraphicsRAM
Phenom II x6 1405T (unlocked Athlon II X4 640T) ASUS M5A99X EVO AM3+ Asus ENGTX470/2DI/1280MD5/V2 16 GB (4x4GB) G.Skill DDR3 1600 CAS9 1.35v 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Blue 250 2.5" Laptop Drive WD Caviar Black 1TB 3.5" Pioneer BDR-203 BluRay Burner Corsair H60 push 
OSOSMonitorPower
Windows 7 Pro x64 Ubuntu 11.10 Samsung 40" 60hz  ANTEC NEO ECO 520W 
CaseMouse
NZXT Gamma Microsoft Bluetooth Notebook Mouse 5000 
CPUMotherboardGraphicsRAM
i7 - 2600k [5.0 1.42v] ASUS P8Z68 Deluxe Sapphire HD6950 2gb Dirt 3 Edition 8GB G.Skill DDR3 2133 CAS11 
Hard DriveOSMonitorKeyboard
60GB G.Skill Sniper + 2x1TB Spinpoint F3 Raid0 Win 7 Pro x64 ASUS VW266H Razer Blackwidow 
PowerCaseMouse
Seasonic X750 Gold Corsair Carbide 500R White G9 
  hide details  
Reply
ShadowForge
(12 items)
 
Defiant
(14 items)
 
CarbonCat
(13 items)
 
CPUMotherboardGraphicsRAM
Phenom II x6 1405T (unlocked Athlon II X4 640T) ASUS M5A99X EVO AM3+ Asus ENGTX470/2DI/1280MD5/V2 16 GB (4x4GB) G.Skill DDR3 1600 CAS9 1.35v 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Blue 250 2.5" Laptop Drive WD Caviar Black 1TB 3.5" Pioneer BDR-203 BluRay Burner Corsair H60 push 
OSOSMonitorPower
Windows 7 Pro x64 Ubuntu 11.10 Samsung 40" 60hz  ANTEC NEO ECO 520W 
CaseMouse
NZXT Gamma Microsoft Bluetooth Notebook Mouse 5000 
CPUMotherboardGraphicsRAM
i7 - 2600k [5.0 1.42v] ASUS P8Z68 Deluxe Sapphire HD6950 2gb Dirt 3 Edition 8GB G.Skill DDR3 2133 CAS11 
Hard DriveOSMonitorKeyboard
60GB G.Skill Sniper + 2x1TB Spinpoint F3 Raid0 Win 7 Pro x64 ASUS VW266H Razer Blackwidow 
PowerCaseMouse
Seasonic X750 Gold Corsair Carbide 500R White G9 
  hide details  
Reply
post #8 of 11
It's just the leading number (1) as a negative number plus the rest of the sequence.

Code:
128 64  32  16  8   4   2   1
1   0   0   0   0   0   0   1 = -127
First 1 signifies -128, and the rest of the sequence signifies the positive numbers, in this case, +1, so -127. All 1's in any sequence would be -1, because all of the numbers before a given number add to total that number -1.
Edited by GoTMaXPoWeR - 4/18/11 at 5:25pm
Lightning
(20 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500K Gigabyte Z68XP-UD3P XFX HD6950 DD 2GB 8GB Corsair Vengeance 1600MHz 
Hard DriveHard DriveHard DriveOptical Drive
Crucial C300 64GB Samsung F2 1.5TB Seagate 500GB LG GH20NS15 
Optical DriveOSMonitorMonitor
Optiarc AD-7261S Win7 64bit 22" LG L226WTQ 19" AOC 
KeyboardPowerCaseMouse
Steelseries 6Gv2  Silverstone ST75F 750W Modular Fractal Design Arc Logitech G500 
Mouse PadAudioAudioAudio
Steelseries QCK Diablo 3 Beyerdynamic DT770 80ohm Fiio E9 Headphone Amp X-Fi XtremeGamer 
  hide details  
Reply
Lightning
(20 items)
 
  
CPUMotherboardGraphicsRAM
i5 2500K Gigabyte Z68XP-UD3P XFX HD6950 DD 2GB 8GB Corsair Vengeance 1600MHz 
Hard DriveHard DriveHard DriveOptical Drive
Crucial C300 64GB Samsung F2 1.5TB Seagate 500GB LG GH20NS15 
Optical DriveOSMonitorMonitor
Optiarc AD-7261S Win7 64bit 22" LG L226WTQ 19" AOC 
KeyboardPowerCaseMouse
Steelseries 6Gv2  Silverstone ST75F 750W Modular Fractal Design Arc Logitech G500 
Mouse PadAudioAudioAudio
Steelseries QCK Diablo 3 Beyerdynamic DT770 80ohm Fiio E9 Headphone Amp X-Fi XtremeGamer 
  hide details  
Reply
post #9 of 11
Quote:
Originally Posted by GoTMaXPoWeR View Post
It's just the leading number (1) as a negative number plus the rest of the sequence.

Code:
64 32 16 8  4  2  1
1  0  0  0  0  0  1 = -127
First 1 signifies -128, and the rest of the sequence signifies the positive numbers, in this case, +1, so -127. All 1's in any sequence would be -1, because all of the numbers before a given number add to total that number -1.
I think you are missing a digit there what you have should be -63
ShadowForge
(12 items)
 
Defiant
(14 items)
 
CarbonCat
(13 items)
 
CPUMotherboardGraphicsRAM
Phenom II x6 1405T (unlocked Athlon II X4 640T) ASUS M5A99X EVO AM3+ Asus ENGTX470/2DI/1280MD5/V2 16 GB (4x4GB) G.Skill DDR3 1600 CAS9 1.35v 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Blue 250 2.5" Laptop Drive WD Caviar Black 1TB 3.5" Pioneer BDR-203 BluRay Burner Corsair H60 push 
OSOSMonitorPower
Windows 7 Pro x64 Ubuntu 11.10 Samsung 40" 60hz  ANTEC NEO ECO 520W 
CaseMouse
NZXT Gamma Microsoft Bluetooth Notebook Mouse 5000 
CPUMotherboardGraphicsRAM
i7 - 2600k [5.0 1.42v] ASUS P8Z68 Deluxe Sapphire HD6950 2gb Dirt 3 Edition 8GB G.Skill DDR3 2133 CAS11 
Hard DriveOSMonitorKeyboard
60GB G.Skill Sniper + 2x1TB Spinpoint F3 Raid0 Win 7 Pro x64 ASUS VW266H Razer Blackwidow 
PowerCaseMouse
Seasonic X750 Gold Corsair Carbide 500R White G9 
  hide details  
Reply
ShadowForge
(12 items)
 
Defiant
(14 items)
 
CarbonCat
(13 items)
 
CPUMotherboardGraphicsRAM
Phenom II x6 1405T (unlocked Athlon II X4 640T) ASUS M5A99X EVO AM3+ Asus ENGTX470/2DI/1280MD5/V2 16 GB (4x4GB) G.Skill DDR3 1600 CAS9 1.35v 
Hard DriveHard DriveOptical DriveCooling
WD Caviar Blue 250 2.5" Laptop Drive WD Caviar Black 1TB 3.5" Pioneer BDR-203 BluRay Burner Corsair H60 push 
OSOSMonitorPower
Windows 7 Pro x64 Ubuntu 11.10 Samsung 40" 60hz  ANTEC NEO ECO 520W 
CaseMouse
NZXT Gamma Microsoft Bluetooth Notebook Mouse 5000 
CPUMotherboardGraphicsRAM
i7 - 2600k [5.0 1.42v] ASUS P8Z68 Deluxe Sapphire HD6950 2gb Dirt 3 Edition 8GB G.Skill DDR3 2133 CAS11 
Hard DriveOSMonitorKeyboard
60GB G.Skill Sniper + 2x1TB Spinpoint F3 Raid0 Win 7 Pro x64 ASUS VW266H Razer Blackwidow 
PowerCaseMouse
Seasonic X750 Gold Corsair Carbide 500R White G9 
  hide details  
Reply
post #10 of 11
Thread Starter 
OK, so while you guys are having fun, i just got to to a point where i have to add a bias of 2,147,483,647 to a number and convert that to binary, that is annoying! do you know how long it takes to do that by hand? it is tedious buy i wanted to make sure i was doing it right before i got to much into it, i just add the number to 2,147,483,647 and convert to binary right?
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › 32 bit signed binary, and two's compliment