Wednesday, April 17, 2019

Integer to it's binary string representation in C

My oldest son is studying mathematics and programming in college and wrote me asking for a way to convert an integer to it's binary representation in C. My C string handling is a bit rusty, but I accepted the challenge. This was the result, maybe it can be useful for someone.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

const char *int_to_binary_string(int);

#define BITS_REQUIRED (sizeof(value_to_convert) * 8)

const char * int_to_binary_string(int value_to_convert) {
  char *result_string = malloc(BITS_REQUIRED + 1);

  for (int bit_counter = BITS_REQUIRED - 1; bit_counter >= 0; bit_counter--) {
    int current_bit = value_to_convert >> bit_counter;
    strcat(result_stringcurrent_bit & 1 ? "1" : "0");
  }

  return strchr(result_string, '1');
}

int main(void) {
  int value_to_convert = 55;
  printf("%i in binary is %s\n", c, int_to_binary_string(value_to_convert));
}

And the output:

{21:32}[2.5.0]~/Desktop ➭ gcc test.c
{21:39}[2.5.0]~/Desktop ➭ ./a.out   
55 in binary is 110111

Wednesday, March 6, 2019

Potentiometer value codes

Just received a potentiometer kit I ordered from Ebay. Off course it all comes in unlabeled small ziplock bags:




But as with most electronic component, potentiometers have small marking or value code on them:


The following is a table that will help you identify the actual value of the said potentiometers:

Code Value
100 10 Ω
200 20 Ω
500 50 Ω
101 100 Ω
201 200 Ω
501 500 Ω
102 1 kΩ
202 2 kΩ
502 5 kΩ
103 10 kΩ
203 20 kΩ
253 25 kΩ
503 50kΩ
104 100 kΩ
204 200 kΩ
254 250 kΩ
504 500 kΩ
105 1 MΩ
205 2 MΩ
505 5 MΩ

Wednesday, January 2, 2019

Electronic devices + password + death = pain

A few months ago my wife's mother died. Being the "teksavvy" guy I had to deal with the disconnection of all-the-things electronics, gather devices that needed to be returned to the ISP,...

Good thing she only had a Windows 10 laptop, no cell phone, no tablet.

But my wife wanted to access what was on the laptop before we wiped it and re-purposed it to a family member.

Only thing was that the person (not me) who set it up for her had configured it with a Microsoft LiveID account. We had a bunch of hand written note with passwords, account ID but could not find a password or PIN that worked to login into her Windows profile.

I had done Windows password reset in the past using a Live CD but it was in the Windows NT era...

The first ISO I used was Hiren’s BootCD PE (I'll spare the details that the laptop is UEFI and does not have a built-in CD/DVD drive and I could not get it to boot on USB). Unfortunately it was not able to reset or remove LiveID account password. But I was able to clear the local Administrator account password and this gaining access to the machine. If all fails we could always at least recuperate the files from there. But I wanted full account access.

After a few Google search I found PC Unlocker. Being a FLOSS advocate I tend to dismiss closed source commercial software. But I did not have much more time to spend on this. So I bought a copy for 32.7$CAD and give it a spin.

Sure enough I was able to remove the user account password. I then rebooted, Windows in all it's glory decided to do a HDD scan and repair (why I don't know), but I was then able to login the account without any passwords.

I would have preferred an open-source free utility, but when time is limited it's sometimes worth it to spend 30$ instead of fiddling for hours.

If you know of any FLOSS tool that can reset/clear LiveID account password on Windows let me know !

As a side note, having many electronic devices, accounts and passwords I'll have to evaluate how to deal with this to ease the way for my relatives when (if I ever lol) pass away.


Integer to it's binary string representation in C

My oldest son is studying mathematics and programming in college and wrote me asking for a way to convert an integer to it's binary repr...